{-# LANGUAGE OverloadedStrings #-}
module Hasmin.Properties (
PropertyInfo(..)
, shorthandAndLonghandsMap
, propertiesTraits
) where
import Data.Attoparsec.Text (parseOnly)
import Data.Text (Text)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Hasmin.Types.Value
import Hasmin.Parser.Value
data PropertyInfo =
PropertyInfo { overwrittenBy :: [Text]
, subproperties :: [Text]
} deriving (Show)
shorthandAndLonghandsMap :: Map Text PropertyInfo
shorthandAndLonghandsMap = Map.fromList properties
properties :: [(Text,PropertyInfo)]
properties =
[("animation", PropertyInfo mempty ["animation-name","animation-duration","animation-timing-function","animation-delay","animation-iteration-count","animation-direction","animation-fill-mode","animation-play-state"])
,("animation-delay", PropertyInfo ["animation"] mempty)
,("animation-direction", PropertyInfo ["animation"] mempty)
,("animation-duration", PropertyInfo ["animation"] mempty)
,("animation-fill-mode", PropertyInfo ["animation"] mempty)
,("animation-iteration-count", PropertyInfo ["animation"] mempty)
,("animation-name", PropertyInfo ["animation"] mempty)
,("animation-play-state", PropertyInfo ["animation"] mempty)
,("animation-timing-function", PropertyInfo ["animation"] mempty)
,("background", PropertyInfo mempty ["background-image", "background-position", "background-size", "background-repeat", "background-origin", "background-clip", "background-attachment", "background-color"])
,("background-attachment", PropertyInfo ["background"] mempty)
,("background-clip", PropertyInfo ["background"] mempty)
,("background-color", PropertyInfo ["background"] mempty)
,("background-image", PropertyInfo ["background"] mempty)
,("background-origin", PropertyInfo ["background"] mempty)
,("background-position", PropertyInfo ["background"] ["background-position-x", "background-position-y"])
,("background-position-x", PropertyInfo ["background", "background-position"] mempty)
,("background-position-y", PropertyInfo ["background", "background-position"] mempty)
,("background-repeat", PropertyInfo ["background"] mempty)
,("background-size", PropertyInfo ["background"] mempty)
,("border", PropertyInfo mempty ["border-width", "border-style", "border-color"])
,("border-bottom", PropertyInfo ["border"] ["border-bottom-color", "border-bottom-style", "border-bottom-width"])
,("border-bottom-color", PropertyInfo ["border", "border-color", "border-bottom"] mempty)
,("border-bottom-left-radius", PropertyInfo ["border-radius"] mempty)
,("border-bottom-right-radius", PropertyInfo ["border-radius"] mempty)
,("border-bottom-style", PropertyInfo ["border", "border-style", "border-bottom"] mempty)
,("border-bottom-width", PropertyInfo ["border", "border-width", "border-bottom"] mempty)
,("border-color", PropertyInfo ["border"] ["border-top-color", "border-right-color", "border-bottom-color", "border-left-color"])
,("border-image", PropertyInfo ["border"] ["border-image-source", "border-image-slice", "border-image-width", "border-image-outset", "border-image-repeat"])
,("border-image-outset", PropertyInfo ["border", "border-image"] mempty)
,("border-image-repeat", PropertyInfo ["border", "border-image"] mempty)
,("border-image-slice", PropertyInfo ["border", "border-image"] mempty)
,("border-image-source", PropertyInfo ["border", "border-image"] mempty)
,("border-image-width", PropertyInfo ["border", "border-image"] mempty)
,("border-left", PropertyInfo ["border"] ["border-left-color", "border-left-style", "border-left-width"])
,("border-left-color", PropertyInfo ["border", "border-color", "border-left"] mempty)
,("border-left-style", PropertyInfo ["border", "border-style", "border-left"] mempty)
,("border-left-width", PropertyInfo ["border", "border-width", "border-left"] mempty)
,("border-radius", PropertyInfo mempty ["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius"])
,("border-right", PropertyInfo ["border"] ["border-right-color", "border-right-style", "border-right-width"])
,("border-right-color", PropertyInfo ["border", "border-color", "border-right"] mempty)
,("border-right-style", PropertyInfo ["border", "border-style", "border-right"] mempty)
,("border-right-width", PropertyInfo ["border", "border-width", "border-right"] mempty)
,("border-style", PropertyInfo ["border"] ["border-top-style", "border-right-style", "border-bottom-style", "border-left-style"])
,("border-top", PropertyInfo ["border"] ["border-top-color", "border-top-style", "border-top-width"])
,("border-top-color", PropertyInfo ["border", "border-color", "border-top"] mempty)
,("border-top-left-radius", PropertyInfo ["border-radius"] mempty)
,("border-top-right-radius", PropertyInfo ["border-radius"] mempty)
,("border-top-style", PropertyInfo ["border", "border-style", "border-top"] mempty)
,("border-top-width", PropertyInfo ["border", "border-width", "border-top"] mempty)
,("border-width", PropertyInfo ["border"] ["border-top-width", "border-right-width", "border-bottom-width", "border-left-width"])
,("column-count", PropertyInfo ["columns"] mempty)
,("column-rule", PropertyInfo mempty ["column-rule-color", "column-rule-style", "column-rule-width"])
,("column-rule-color", PropertyInfo ["column-rule"] mempty)
,("column-rule-style", PropertyInfo ["column-rule"] mempty)
,("column-rule-width", PropertyInfo ["column-rule"] mempty)
,("columns", PropertyInfo mempty ["column-width", "column-count"])
,("column-width", PropertyInfo ["columns"] mempty)
,("flex", PropertyInfo mempty ["flex-grow", "flex-shrink", "flex-basis"])
,("flex-basis", PropertyInfo ["flex"] mempty)
,("flex-direction", PropertyInfo ["flex-flow"] mempty)
,("flex-flow", PropertyInfo mempty ["flex-direction", "flex-wrap"])
,("flex-grow", PropertyInfo ["flex"] mempty)
,("flex-shrink", PropertyInfo ["flex"] mempty)
,("flex-wrap", PropertyInfo ["flex-flow"] mempty)
,("font", PropertyInfo mempty ["font-style", "font-variant", "font-weight", "font-stretch", "font-size", "line-height", "font-family"])
,("font-family", PropertyInfo ["font"] mempty)
,("font-kerning", PropertyInfo ["font"] mempty)
,("font-language-override", PropertyInfo ["font"] mempty)
,("font-size", PropertyInfo ["font"] mempty)
,("font-size-adjust", PropertyInfo ["font"] mempty)
,("font-stretch", PropertyInfo ["font"] mempty)
,("font-style", PropertyInfo ["font"] mempty)
,("font-variant", PropertyInfo ["font"] mempty)
,("font-weight", PropertyInfo ["font"] mempty)
,("grid", PropertyInfo mempty ["grid-template-rows", "grid-template-columns", "grid-template-areas", "grid-auto-rows", "grid-auto-columns", "grid-auto-flow", "grid-column-gap", "grid-row-gap"])
,("grid-area", PropertyInfo mempty ["grid-row-start", "grid-row-end", "grid-column-start", "grid-column-end"])
,("grid-column", PropertyInfo mempty ["grid-column-start", "grid-column-end"])
,("grid-column-end", PropertyInfo ["grid-column", "grid-area"] mempty)
,("grid-column-end", PropertyInfo ["grid-column", "grid-area"] mempty)
,("grid-column-gap", PropertyInfo ["grid-gap"] mempty)
,("grid-gap", PropertyInfo mempty ["grid-row-gap", "grid-column-gap"])
,("grid-row", PropertyInfo mempty ["grid-row-start", "grid-row-end"])
,("grid-row-end", PropertyInfo ["grid-row", "grid-area"] mempty)
,("grid-row-gap", PropertyInfo ["grid-gap"] mempty)
,("grid-row-start", PropertyInfo ["grid-row", "grid-area"] mempty)
,("grid-template", PropertyInfo mempty ["grid-template-columns", "grid-template-rows", "grid-template-areas"])
,("grid-template-areas", PropertyInfo ["grid-template"] mempty)
,("grid-template-columns", PropertyInfo ["grid-template"] mempty)
,("grid-template-rows", PropertyInfo ["grid-template"] mempty)
,("line-height", PropertyInfo ["font"] mempty)
,("list-style", PropertyInfo mempty ["list-style-type", "list-style-position", "list-style-image"])
,("list-style-image", PropertyInfo ["list-style"] mempty)
,("list-style-position", PropertyInfo ["list-style"] mempty)
,("list-style-type", PropertyInfo ["list-style"] mempty)
,("margin", PropertyInfo mempty ["margin-top", "margin-right", "margin-bottom", "margin-left"])
,("margin-bottom", PropertyInfo ["margin"] mempty)
,("margin-left", PropertyInfo ["margin"] mempty)
,("margin-right", PropertyInfo ["margin"] mempty)
,("margin-top", PropertyInfo ["margin"] mempty)
,("mask", PropertyInfo mempty ["mask-clip", "mask-origin", "mask-border"])
,("mask-border", PropertyInfo ["mask"] ["mask-border-source", "mask-border-slice", "mask-border-width", "mask-border-outset", "mask-border-repeat"])
,("mask-border-outset", PropertyInfo ["mask", "mask-border"] mempty)
,("mask-border-repeat", PropertyInfo ["mask", "mask-border"] mempty)
,("mask-border-slice", PropertyInfo ["mask", "mask-border"] mempty)
,("mask-border-source", PropertyInfo ["mask", "mask-border"] mempty)
,("mask-border-width", PropertyInfo ["mask", "mask-border"] mempty)
,("mask-clip", PropertyInfo ["mask"] mempty)
,("mask-composite", PropertyInfo ["mask"] mempty)
,("mask-image", PropertyInfo ["mask"] mempty)
,("mask-mode", PropertyInfo ["mask"] mempty)
,("mask-origin", PropertyInfo ["mask"] mempty)
,("mask-position", PropertyInfo ["mask"] mempty)
,("mask-repeat", PropertyInfo ["mask"] mempty)
,("mask-size", PropertyInfo ["mask"] mempty)
,("outline", PropertyInfo mempty ["outline-width", "outline-style", "outline-color"])
,("outline-color", PropertyInfo ["outline"] mempty)
,("outline-style", PropertyInfo ["outline"] mempty)
,("outline-width", PropertyInfo ["outline"] mempty)
,("padding", PropertyInfo mempty ["padding-top", "padding-right", "padding-bottom", "padding-left"])
,("padding-bottom", PropertyInfo ["padding"] mempty)
,("padding-left", PropertyInfo ["padding"] mempty)
,("padding-right", PropertyInfo ["padding"] mempty)
,("padding-top", PropertyInfo ["padding"] mempty)
,("text-decoration", PropertyInfo mempty ["text-decoration-color", "text-decoration-style", "text-decoration-line"])
,("text-decoration-color", PropertyInfo ["text-decoration"] mempty)
,("text-decoration-line", PropertyInfo ["text-decoration"] mempty)
,("text-decoration-style", PropertyInfo ["text-decoration"] mempty)
,("text-emphasis", PropertyInfo mempty ["text-emphasis-color", "text-emphasis-style"])
,("text-emphasis-color", PropertyInfo ["text-emphasis"] mempty)
,("text-emphasis-style", PropertyInfo ["text-emphasis"] mempty)
,("transition", PropertyInfo mempty ["transition-property", "transition-duration", "transition-timing-function", "transition-delay"])
,("transition-delay", PropertyInfo ["transition"] mempty)
,("transition-duration", PropertyInfo ["transition"] mempty)
,("transition-property", PropertyInfo ["transition"] mempty)
,("transition-timing-function", PropertyInfo ["transition"] mempty)
]
propertiesTraits :: Map Text (Maybe Values, Bool)
propertiesTraits = Map.fromList $ replaceTextWithValues
[("align-content", ("stretch", False))
,("align-items", ("stretch", False))
,("align-self", ("auto", False))
,("all", (mempty, False))
,("animation", (mempty, False))
,("animation-delay", ("0s", False))
,("animation-direction", ("normal", False))
,("animation-duration", ("0s", False))
,("animation-fill-mode", ("none", False))
,("animation-iteration-count", ("1", False))
,("animation-name", ("none", False))
,("animation-play-state", ("running", False))
,("animation-timing-function", ("ease", False))
,("backface-visibility", ("visible", False))
,("-webkit-backface-visibility", ("visible", False))
,("backdrop-filter", ("none", False))
,("-webkit-backdrop-filter", ("none", False))
,("background", (mempty , False))
,("background-attachment", ("scroll", False))
,("background-blend-mode", ("normal", False))
,("background-clip", ("border-box", False))
,("-webkit-background-clip", ("border-box", False))
,("background-color", ("transparent", False))
,("background-image", ("none", False))
,("background-origin", ("padding-box", False))
,("background-position", (mempty, False))
,("background-position-x", ("left", False))
,("background-position-inline", (mempty , False))
,("background-position-block", (mempty , False))
,("background-position-y", ("top", False))
,("background-repeat", ("repeat", False))
,("background-size", ("auto", False))
,("block-size", ("auto", False))
,("border", ("medium none currentcolor", False))
,("border-bottom", ("medium none currentcolor", False))
,("border-bottom-color", ("currentcolor", False))
,("border-bottom-left-radius", ("0", False))
,("border-bottom-right-radius", ("0", False))
,("border-bottom-style", ("none", False))
,("border-bottom-width", ("medium", False))
,("border-collapse", ("separate", True))
,("border-color", (mempty, False))
,("border-image", (mempty, False))
,("border-image-outset", ("0", False))
,("border-image-repeat", ("stretch", False))
,("border-image-slice", ("100%", False))
,("border-image-source", ("none", False))
,("border-image-width", ("1", False))
,("border-left", ("medium none currentcolor", False))
,("border-left-color", ("currentcolor", False))
,("border-left-style", ("none", False))
,("border-left-width", ("medium", False))
,("border-right", ("medium none currentcolor", False))
,("border-right-color", ("currentcolor", False))
,("border-right-style", ("none", False))
,("border-right-width", ("medium", False))
,("border-spacing", ("0", True))
,("border-top", ("medium none currentcolor", False))
,("border-top-color", ("currentcolor", False))
,("border-top-style", ("none", False))
,("border-top-width", ("medium", False))
,("border-top-left-radius", ("0", False))
,("border-top-right-radius", ("0", False))
,("bottom", ("auto", False))
,("box-decoration-break", ("slice", False))
,("-webkit-box-decoration-break", ("slice", False))
,("-o-box-decoration-break", ("slice", False))
,("box-shadow", ("none", False))
,("-webkit-box-shadow", ("none", False))
,("box-sizing", ("content-box", False))
,("-webkit-box-sizing", ("content-box", False))
,("-moz-box-sizing", ("content-box", False))
,("break-after", ("auto", False))
,("break-before", ("auto", False))
,("break-inside", ("auto", False))
,("caption-side", ("top", True))
,("clear", ("none", False))
,("clip", ("auto", False))
,("color", (mempty , True))
,("column-count", ("auto", False))
,("column-fill", ("balance", False))
,("column-gap", ("normal", False))
,("column-rule", ("medium none currentcolor", False))
,("column-rule-color", ("currentcolor", False))
,("column-rule-style", ("none", False))
,("column-rule-width", ("medium", False))
,("column-span", ("none", False))
,("column-width", ("auto", False))
,("content", ("normal", False))
,("counter-increment", ("none", False))
,("counter-reset", ("none", False))
,("cursor", ("auto", True))
,("direction", ("ltr", True))
,("display", ("inline", False))
,("empty-cells", ("show", True))
,("filter", ("none", False))
,("-webkit-filter", ("none", False))
,("flex-basis", ("auto", False))
,("flex-direction", ("row", False))
,("flex-flow", ("row nowrap", False))
,("flex-grow", ("0", False))
,("flex-shrink", ("1", False))
,("flex-wrap", ("nowrap", False))
,("float", ("none", False))
,("float", ("none", False))
,("font", (mempty , True))
,("font-family", (mempty , True))
,("font-feature-settings", ("normal", True))
,("font-kerning", ("auto", True))
,("font-language-override", ("normal", True))
,("font-size", ("medium", True))
,("font-size-adjust", ("none", True))
,("font-stretch", ("normal", True))
,("font-style", ("normal", True))
,("font-synthesis", ("weight style", True))
,("font-variant", ("normal", True))
,("font-variant-alternates", ("normal", True))
,("font-variant-caps", ("normal", True))
,("font-variant-east-asian", ("normal", True))
,("font-variant-ligatures", ("normal", True))
,("font-variant-numeric", ("normal", True))
,("font-variant-position", ("normal", True))
,("font-weight", ("normal", True))
,("grid-auto-columns", ("auto", False))
,("-ms-grid-auto-columns", ("auto", False))
,("-webkit-grid-auto-columns", ("auto", False))
,("grid-auto-flow", ("row", False))
,("-webkit-grid-auto-flow", ("row", False))
,("grid-auto-rows", ("auto", False))
,("-ms-grid-auto-rows", ("auto", False))
,("-webkit-grid-auto-rows", ("auto", False))
,("grid-column-end", ("auto", False))
,("-ms-grid-column-end", ("auto", False))
,("-webkit-grid-column-end", ("auto", False))
,("grid-column-gap", ("0", False))
,("-ms-grid-column-gap", ("0", False))
,("grid-column-start", ("auto", False))
,("-ms-grid-column-start", ("auto", False))
,("-webkit-grid-column-start", ("auto", False))
,("grid-row-end", ("auto", False))
,("-ms-grid-row-end", ("auto", False))
,("-webkit-grid-row-end", ("auto", False))
,("grid-row-gap", ("0", False))
,("-webkit-grid-row-gap", ("0", False))
,("grid-row-start", ("auto", False))
,("-ms-grid-row-start", ("auto", False))
,("-webkit-grid-row-start", ("auto", False))
,("grid-template-areas", ("none", False))
,("-webkit-grid-template-areas", ("none", False))
,("grid-template-columns", ("none", False))
,("-ms-grid-template-columns", ("none", False))
,("-webkit-grid-template-columns", ("none", False))
,("grid-template-rows", ("none", False))
,("-ms-grid-template-rows", ("none", False))
,("-webkit-grid-template-rows", ("none", False))
,("height", ("auto", False))
,("hyphens", ("manual", False))
,("isolation", ("auto", False))
,("justify-content", ("flex-start", False))
,("left", ("auto", False))
,("letter-spacing", ("normal", True))
,("line-break", ("auto", False))
,("line-height", ("normal", True))
,("list-style", ("none disc outside", True))
,("list-style-image", ("none", True))
,("list-style-position", ("outside", True))
,("list-style-type", ("disc", True))
,("margin", (mempty , False))
,("margin-bottom", ("0", False))
,("margin-left", ("0", False))
,("margin-right", ("0", False))
,("margin-top", ("0", False))
,("mask-clip", ("border-box", False))
,("-webkit-mask-clip", ("border-box", False))
,("mask-composite", ("add", False))
,("mask-image", ("none", False))
,("-webkit-mask-image", ("none", False))
,("mask-origin", ("border-box", False))
,("-webkit-mask-origin", ("border-box", False))
,("mask-position", ("center", False))
,("-webkit-mask-position", ("center", False))
,("mask-repeat", ("no-repeat", False))
,("-webkit-mask-repeat", ("no-repeat", False))
,("mask-size", ("auto", False))
,("mask-type", ("luminance", False))
,("max-height", ("none", False))
,("max-width", ("none", False))
,("min-height", ("0", False))
,("min-width", ("0", False))
,("mix-blend-mode", ("normal", False))
,("object-fit", ("fill", True))
,("object-position", ("50% 50%", True))
,("opacity", ("1", False))
,("order", ("0", False))
,("orphans", ("2", True))
,("outline", ("medium none invert", False))
,("outline-color", ("invert" , False))
,("outline-offset", ("0", False))
,("outline-style", ("none", False))
,("outline-width", ("medium", False))
,("overflow", ("visible", False))
,("overflow-wrap", ("normal", True))
,("overflow-x", ("visible", False))
,("overflow-y", ("visible", False))
,("padding", (mempty, False))
,("padding-bottom", ("0", False))
,("padding-left", ("0", False))
,("padding-right", ("0", False))
,("padding-top", ("0", False))
,("page-break-after", ("auto", False))
,("page-break-before", ("auto", False))
,("page-break-inside", ("auto", False))
,("perspective", ("none", False))
,("perspective-origin", ("50% 50%", False))
,("pointer-events", ("auto", True))
,("position", ("static", False))
,("quotes", (mempty , True))
,("resize", ("none", False))
,("right", ("auto", False))
,("right", ("auto", False))
,("scroll-behavior", ("auto", False))
,("shape-image-threshold", ("0", False))
,("shape-margin", ("0", False))
,("shape-outside", ("none", False))
,("tab-size", ("8", True))
,("-moz-tab-size", ("8", True))
,("-o-tab-size", ("8", True))
,("table-layout", ("auto", False))
,("text-align", ("start", False))
,("text-align-last", ("auto", True))
,("text-combine-upright", ("none", True))
,("-webkit-text-combine-upright", ("none", True))
,("text-decoration", ("currentcolor solid none", False))
,("text-decoration-color", ("currentcolor", False))
,("text-decoration-line", ("none", False))
,("text-decoration-style", ("solid", False))
,("text-emphasis", ("none currentcolor", False))
,("text-emphasis-color", ("currentcolor", False))
,("text-emphasis-position", (mempty , False))
,("text-emphasis-style", ("none", False))
,("text-indent", ("0", True))
,("text-orientation", ("mixed", True))
,("-webkit-text-orientation", ("mixed", True))
,("text-overflow", ("clip", False))
,("text-rendering", ("auto", True))
,("text-shadow", ("none", True))
,("text-transform", ("none", True))
,("text-underline-position", ("auto", True))
,("top", ("auto", False))
,("touch-action", ("auto", False))
,("transform", ("none", False))
,("-webkit-transform", ("none", False))
,("transform-box", ("border-box", False))
,("transform-origin", (mempty , False))
,("-webkit-transform-origin", (mempty , False))
,("transform-style", ("flat", False))
,("-webkit-transform-style", ("flat", False))
,("transition", (mempty, False))
,("transition-delay", ("0s", False))
,("transition-duration", ("0s", False))
,("-webkit-transition-duration", ("0s", False))
,("-o-transition-duration", ("0s", False))
,("-webkit-transition-delay", ("0s", False))
,("transition-property", ("all", False))
,("-webkit-transition-property", ("all", False))
,("-o-transition-property", ("all", False))
,("transition-timing-function", ("ease", False))
,("-webkit-transition-timing-function", ("ease", False))
,("unicode-bidi", ("normal", False))
,("user-select", ("none", False))
,("-moz-user-select", ("none", False))
,("-webkit-user-select", ("none", False))
,("-ms-user-select", ("none", False))
,("vertical-align", ("baseline", False))
,("white-space", ("normal", True))
,("widows", ("2", True))
,("width", ("auto", False))
,("will-change", ("auto", False))
,("word-break", ("normal", True))
,("word-spacing", ("normal", True))
,("writing-mode", ("horizontal-tb", True))
,("-ms-writing-mode", ("horizontal-tb", True))
,("-webkit-writing-mode", ("horizontal-tb", True))
,("z-index", ("auto", False))
]
replaceTextWithValues :: [(Text, (Text, Bool))] -> [(Text, (Maybe Values, Bool))]
replaceTextWithValues = foldr (\(p,(t,i)) xs -> (p, (getValues p t,i)) : xs) []
where getValues p s = case parseOnly (values p) s of
Right initialValues -> Just initialValues
Left _ -> Nothing