Right now there isn't a way to represent CSS vendor prefixes since attributes (Called Name) must be unique. For example, there isn't a way to write this CSS:
{
background: -webkit-linear-gradient(left, #fff, #000);
background: -moz-linear-gradient(left, #fff, #000);
background: -ms-linear-gradient(left, #fff, #000);
background: -o-linear-gradient(left, #fff, #000);
background: linear-gradient(to right, #fff, #000);
}
One way to fix this is to add a Prefixed option to StyleValue. For example:
newtype Prefix = Prefix { unPrefix :: Text }
data StyleValue
= Prefixed (NEMap Prefix Text)
| Plain Text
This is similar to the way Clay handles prefixes, but with a non-empty map to better represent the data and make writing the Semigroup instance easy.
However, we still need to handle prefixes in attributes (Name):
{
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
We can represent this with just Map Name StyleValue, but it makes adding prefixes to attribute names cumbersome. We can learn from Clay by creating a separate Prefixed type:
newtype Prefix = Prefix { unPrefix :: Text }
data Prefixed
= Prefixed (NEMap Prefix Text)
| Plain Text
Then making both StyleValue and Name newtype of Prefixed:
newtype StyleValue = StyleValue { unStyleValue :: Prefixed }
newtype Name = Name { unName :: Prefixed }
newtype Styles = Styles { unStyles :: Map Name StyleValue }
We need to make Styles a newtype to change the Semigroup instance so prefixes are not mixed and matched when combining.
Although this change touches a lot of code, most functions will just use the Plain version and not change functionally. We will gain a addBrowerPrefix function and can create Mod that have builtin prefixes. Let me know what you think about the types, I'll draft a PR afterwards.
Right now there isn't a way to represent CSS vendor prefixes since attributes (Called
Name) must be unique. For example, there isn't a way to write this CSS:One way to fix this is to add a
Prefixedoption toStyleValue. For example:This is similar to the way Clay handles prefixes, but with a non-empty map to better represent the data and make writing the
Semigroupinstance easy.However, we still need to handle prefixes in attributes (
Name):We can represent this with just
Map Name StyleValue, but it makes adding prefixes to attribute names cumbersome. We can learn from Clay by creating a separatePrefixedtype:Then making both
StyleValueandNamenewtype ofPrefixed:We need to make
Stylesa newtype to change theSemigroupinstance so prefixes are not mixed and matched when combining.Although this change touches a lot of code, most functions will just use the
Plainversion and not change functionally. We will gain aaddBrowerPrefixfunction and can createModthat have builtin prefixes. Let me know what you think about the types, I'll draft a PR afterwards.