Skip to content

Add Support for vendor prefix #15

@Skyfold

Description

@Skyfold

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions