Skip to content

Better conversion CSS linear-gradient() #589

Description

@yisibl

Now

Input:

.foo {
  background-image: linear-gradient(to bottom, #f8f8f8, #eeeeee);
}

Output:

.foo {
  background-image: -webkit-gradient(linear, left top, left bottom, from(#f8f8f8), to(#eeeeee));
  background-image: -webkit-linear-gradient(top, #f8f8f8, #eeeeee);
  background-image: -moz-linear-gradient(top, #f8f8f8, #eeeeee);
  background-image: -o-linear-gradient(top, #f8f8f8, #eeeeee);
  background-image: linear-gradient(to bottom, #f8f8f8, #eeeeee);
}

But

Input:

.foo {
  background-image: linear-gradient(180deg, #f8f8f8, #eeeeee);
}

Output:

.foo {
  background-image: -webkit-linear-gradient(top, #f8f8f8, #eeeeee);
  background-image: -moz-linear-gradient(top, #f8f8f8, #eeeeee);
  background-image: -o-linear-gradient(top, #f8f8f8, #eeeeee);
  background-image: linear-gradient(to bottom, #f8f8f8, #eeeeee);
}

Lost:

  background-image: -webkit-gradient(linear, left top, left bottom, from(#f8f8f8), to(#eeeeee));

We need to support 0deg, 90deg,180deg, 270deg, 360deg, converted to WebKit's oldest syntax.

That is to say:

to bottom = 180deg = top = left top, left bottom

If the argument is to top, to right, to bottom, or to left, the angle of the gradient line is 0deg, 90deg, 180deg, or 270deg, respectively.
https://drafts.csswg.org/css-images/#linear-gradients

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions