Skip to content

[css-color-4] Allow percent as well as float 0.0 to 1.0 in color() args #3450

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

Closed
svgeesus opened this issue Dec 17, 2018 · 11 comments
Closed
Assignees
Labels
css-color-4 Current Work

Comments

@svgeesus
Copy link
Contributor

@faceless2 said

allowing a percentage as a synonym for 0..1 may be more natural, e.g. color(swopc 0 85% 70% 42%)

which is worthy of separate discussion.

@svgeesus svgeesus added the css-color-4 Current Work label Dec 17, 2018
@ghost
Copy link

ghost commented Jan 30, 2019

The spec already allows this for several types: namely <rgb-component> and <alpha-value> in the rgba() function. So I think that it would be natural to define it as a <number-percentage>. The change still allows the full range of real numbers to be used, just in a different format. ie. 300% = 3 or 450% = 4.5, etc..

@svgeesus svgeesus self-assigned this Feb 6, 2019
@svgeesus
Copy link
Contributor Author

While allowing, say, 50% as a synonym for 0.5 seems unproblematic, doing so would impact #278 were @tabatkins argues for adding percentage units to the L* value. So 50 and 50% would be synonymous, except now the spec would need to clarify that here, 50% means 50 not 0.5.

Apart from that one issue, I don't see an issue with allowing percentage units as well as floats here. I don't want to hold up this issue for #278 so I'm going to agree with @faceless2 here and solve that other issue separately.

@svgeesus
Copy link
Contributor Author

Existing tests need to be updated to also check the percentage values.

@svgeesus
Copy link
Contributor Author

This change would also affect the gray() notation, which takes a number in the range [0,100] for example gray(50). If percentages were optional, the spec would need to specify that gray(50%) meant gray(50) not gray(0.5) which is very different.

@svgeesus
Copy link
Contributor Author

With the recent resolution to 4649 adding lab to the color() function, this issue would require stating that all percentages resolve to 0.0 .. 1.0 except that for lab the first percentage resolves to 0.0 to 100.0.

@Crissov
Copy link
Contributor

Crissov commented Jan 20, 2020

Why, though?

L* in Lab() has always been a percentage, it is just often written without the percent sign outside CSS. This is already noted in the spec as a result of #4477.

@svgeesus
Copy link
Contributor Author

Because all the other percentages resolve to 0.0 to 1.0, and because this issue is as well as

@Crissov
Copy link
Contributor

Crissov commented Jan 23, 2020

So does L* in lab(…) and color(lab,…). Itʼs always 100% = 1.0 = 1 within CSS; only outside CSS you would ever encounter 100.0 = 100 = 100%.

I see no WG resolution to make lab(50 …) or color(lab, 50 …) resolve to the same color as lab(0.5 …) or color(lab, 0.5 …). They might be clamped to lab(1.0 …) or lab(100% …) though.

@svgeesus
Copy link
Contributor Author

Percentages as well as floats were added in Allow percent as well as float 0.0 to 1.0 in color() args

@svgeesus
Copy link
Contributor Author

@svgeesus
Copy link
Contributor Author

WPT tests for color() in progress

Tests now updated to take into account review feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-color-4 Current Work
Projects
None yet
Development

No branches or pull requests

2 participants