Skip to content
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

[css-color-5] For color-mix(), what should happen if you provide an adjuster without a paired percent? #6046

Closed
weinig opened this issue Feb 27, 2021 · 6 comments

Comments

@weinig
Copy link
Contributor

weinig commented Feb 27, 2021

In CSS Color 5's color-mix() function, https://drafts.csswg.org/css-color-5/#color-mix, what should happen if an adjuster is specified without a percentage. For example:

color-mix(lch, red lightness, blue);

The grammar for color-adjuster allows this:

<color-adjuster> = [ [
      <srgb-adjuster> | <hsl-adjuster> | <hwb-adjuster>
    | <xyz-adjuster> | <lab-adjuster> | <lch-adjuster>
  ] | alpha ] <percentage>?

due to the "?" after , but I am unclear what the semantics are of that.

In my investigative implementation, I treat an adjuster without a percentage as equivalent to specifying 0% for that adjuster, so for the example above, it would be equivalent to:

color-mix(lch, red lightness 0%, blue);

but I am not convinced this is the intention of the spec authors.

@smfr smfr added the css-color-5 Color modification label Mar 1, 2021
@Myndex
Copy link
Member

Myndex commented Mar 1, 2021

Hmmm.... IMO it should be 100% for the specified adjuster, and then ALL OTHER adjusters are 0%.

Consider in an image editing application where you have a transfer mode for one layer to another, such as "lightness" where only the lightness attribute of the layer is applied to he underlying layer.

@samweinig
Copy link

I guess I should mention my preference as well.

I don't see any reason for this to be valid at all. Seems like we should change the <percentage>? to be just <percentage>.

@svgeesus
Copy link
Contributor

svgeesus commented Mar 2, 2021

The handling of percentages is described in the list following "Arguments are normalized as follows:"

  1. When a percentage is specified without any color-adjusters, it is expanded to all adjusters available for the given colorspace plus alpha.

  2. If a percentage is omitted and there are no adjusters present on any color arguments, it defaults to 50% (an equal mix of the two colors).

  3. Adjusters that are not present on a color default to 0% (i.e. the corresponding components are taken from the other color).

  4. Adjusters that are only present on one of the colors default to 100% - p on the second color, where p is the percentage of the corresponding adjuster in the other color.

  5. If the sum of corresponding adjusters across all colors is not 100%, percentages are scaled proportionally so that the sum is exactly 100%

@svgeesus
Copy link
Contributor

svgeesus commented Mar 2, 2021

The case you are mentioning (adjuster is present, it has no percentage) seems to be item 2 in that list. But perhaps that wasn't clear?

The intent is that you can do color-mix(peru, lightgoldenrod) and get color-mix(peru 50%, lightgoldenrod); a percent is only needed if you want an unequal mixture.

I'm fine requiring an explicit 50%, if we decide on that; or simply adding what I typed above as the first, simplest, example.

@samweinig
Copy link

The case I was referencing was a percentage after an adjuster, which I don't think item 2 refers to as item to states:

If a percentage is omitted and there are no adjusters present on any color arguments, it defaults to 50% (an equal mix of the two colors).

That said, since adjusters have been removed from color-mix(), the concern is no longer relevant. (Though, if color-adjusters are going to be used for color-adjust(), I think requiring the percentage probably does make sense. The spec is kind of in an odd state right now where color-adjust() references the color-adjuster production but it is no longer defined anywhere).

I think we are good to close this issue. Thanks for reviewing it.

@LeaVerou
Copy link
Member

LeaVerou commented Mar 2, 2021

Since per editor resolution we removed adjusters from color-mix(), I'm going to go ahead and close this issue.

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

No branches or pull requests

6 participants