New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove color math #2144

Closed
nex3 opened this Issue Sep 19, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@nex3
Contributor

nex3 commented Sep 19, 2016

Sass's support for mathematical operations on RGB colors is misleading and not very useful. Channel-by-channel arithmetic is very difficult to use effectively when trying to produce a given human-comprehensible color transformation, and in all cases the color functions are better suited to the job.

We should begin by emitting a deprecation warning whenever a binary operation is performed for the +, *, -, /, or % operators when one of the operands is a color and the other is either a color or a number. Once the deprecation period is up, we should make all previously-deprecated operations emit errors.

It would be more consistent with the behavior of +, -, and / on other types to have them emit strings for colors once the deprecation period is over. Nevertheless, I think erroring out is the right thing to do. It makes it clearer that something's going wrong for anyone who didn't see the deprecation warnings, and I don't think there are any real use-cases for using those operators in a stringifying way.

Tasks:

  • Deprecate existing behavior in stable.
  • Remove behavior from master.

nex3 added a commit to sass/sass-spec that referenced this issue Dec 19, 2016

Update specs for sass/sass#2144.
This marks specs that include color arithmetic as incompatible with 4.0,
and adds 4.0-specific specs that assert color arithmetic failures.

nex3 added a commit to sass/sass-spec that referenced this issue Dec 19, 2016

Update specs for sass/sass#2144.
This marks specs that include color arithmetic as incompatible with 4.0,
and adds 4.0-specific specs that assert color arithmetic failures.

nex3 added a commit to sass/sass-spec that referenced this issue Dec 19, 2016

Update specs for sass/sass#2144.
This marks specs that include color arithmetic as incompatible with 4.0,
and adds 4.0-specific specs that assert color arithmetic failures.

nex3 added a commit to sass/sass-spec that referenced this issue Dec 19, 2016

Update specs for sass/sass#2144.
This marks specs that include color arithmetic as incompatible with 4.0,
and adds 4.0-specific specs that assert color arithmetic failures.

nex3 added a commit to sass/sass-spec that referenced this issue Jun 2, 2017

nex3 added a commit that referenced this issue Jun 2, 2017

nex3 added a commit that referenced this issue Jun 2, 2017

nex3 added a commit that referenced this issue Jun 2, 2017

nex3 added a commit that referenced this issue Jun 2, 2017

nex3 added a commit that referenced this issue Jun 3, 2017

nex3 added a commit to sass/sass-spec that referenced this issue Jun 3, 2017

@nex3 nex3 modified the milestone: 4.0 Jun 15, 2017

nex3 added a commit that referenced this issue Jun 16, 2017

nex3 added a commit to sass/sass-spec that referenced this issue Jun 16, 2017

nex3 added a commit that referenced this issue Jun 16, 2017

nex3 added a commit to sass/sass-spec that referenced this issue Jun 16, 2017

@nex3 nex3 closed this Jun 16, 2017

@mgreter mgreter referenced this issue Mar 17, 2018

Merged

Allow mod 0 #1229

@binki

This comment has been minimized.

binki commented Apr 9, 2018

Could you please explain how to port each sass-3 color math operation to a sass-4 equivalent? It is hard to port code when it is unclear how the functions work. Here I try for subtraction:

After much experimentation, I figured out how to port code using the subtraction operator to sass-4:

Original:

.a {
  x: white - grey;
}

Modified:

.a {
  x: adjust_color(white, $red: -(red(grey)), $green: -(green(grey)), $blue: -(blue(grey)));
}

Output:

.a {
  x: #7f7f7f;
}

I find the new code quite needlessly verbose. I’m going to file a bug asking for a new subtract_color() function I guess because that would be helpful and result in much clearer code.

@binki

This comment has been minimized.

binki commented Apr 9, 2018

I’ve put example functions which implement all the operators except for mod in #2501

@justablob

This comment has been minimized.

justablob commented Oct 26, 2018

I disagree with the reasons OP has given. While #fff - 10% might not look like it could make sense to anyone, it is quite obvious that it darkens it by 10%. It is much easier to type that than darken(#fff, 10%). I think the feature should be depreciated, however i'd like some way to enable it for those who actually use it. We want to make styling apps easier and faster after all, right? I hope this is reconsidered to some extent, it would really cheer up my dev team and me.

My 2 cents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment