-
Notifications
You must be signed in to change notification settings - Fork 715
[css-color-4] Specified value for color when calc() is used #8318
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
Comments
That seems fairly clear (and implies that Safari and Firefox are wrong here and should change). I can add some examples of serializing specified and computed values using calc to CSS Color 4 and 5, but the normative reference would be CSS Values. The part about maintaining clamping behavior is less clear. If I have
does the specified value serialize as |
Chrome does the same (test) |
https://drafts.csswg.org/css-values/#calc-range
|
OK I will add an example showing a |
Untagging from Values 4, since everything should be well-defined there. If we end up needing to do something special for calcs in legacy color functions, we will need a Values edit, so tag it back in that case. |
Do you (all) mean that math functions should not be preserved when converting HSL to RGB? An alternative would be to serialize the HSL color when it contains math functions. |
Leaving this open because of the open question regarding serializing a specified |
Minor precision: the question is also about serializing a specified |
Tagging Agenda+ to get discussion on serializing calc-containing |
The CSS Working Group just discussed The full IRC log of that discussion<fantasai> emilio: Clamped at specified value time in the past, unsure if we can change. Not sure about hsl() etc.<fantasai> emilio: but we may want something special for rgb() <fantasai> emilio: might be able to change what spec requires, but also not super excited about it <fantasai> emilio: all browsers are interoperable right now on the weird thing <fantasai> TabAtkins: No strong opinion, but in some cases impossible to resolve calc() until later time <fantasai> TabAtkins: current spec rules define that <fantasai> TabAtkins: I'm OK to define earlier resolution behavior for certain color functions <fantasai> TabAtkins: but suggest take it back up once there's a concrete proposal for what to do <fantasai> TabAtkins: given Chris isn't here, would prefer to have a proposed resolution prepared |
Summarizing current browser behavior when serializing specified values:
let test = document.createElement("div");
test.style.color = "rgb(calc(255), 127, 255)";
console.log(test.style.color);
test.style.color = "rgb(calc(100 * 5), 127, 255)";
console.log(test.style.color);
let test = document.createElement("div");
test.style.color = "hsl(90, calc(100%), 50%)";
console.log(test.style.color);
test.style.color = "hsl(90, calc(100% + 50%), 50%)";
console.log(test.style.color);
let test = document.createElement("div");
test.style.color = "hwb(90 calc(30%) 70%)";
console.log(test.style.color);
test.style.color = "hwb(90 calc(30% * 2) calc(70% * 2)";
console.log(test.style.color); Result per CSS Color 4 sample code (see live test) is
NOT INTEROPERABLE Chrome follows the spec on normalizing over-range W and B while Firefox and Safari give an odd result:
|
Modern syntax Modern syntax |
Proposed resolution: For historical reasons, early resolution of @tabatkins Would that require an 'except as over-ridden by other specifications' in Values 4? Note that the combination of early resolution and early clamping also deals with annoyances like let test = document.createElement("div");
test.style.color = "rgb(calc(255) 127 255)";
console.log(test.style.color);
test.style.color = "rgb(calc(1 / 0) 127 255)";
console.log(test.style.color);
|
@tabatkins ping ahead of this week's call for the values-4 question. @astearns @atanassov Hoping we can resolve this week, as we didn't quite get to this item last week. |
I'd probably add something in V&U saying that some contexts perform "simplification" at specified-value time. Would just be a one-liner somewhere, won't really affect what Color has to say. |
The CSS Working Group just discussed
The full IRC log of that discussion<chris> q+<astearns> ack chris <emeyer> chris: I have a proposed resolution in the issue <emeyer> …Go with what’s implemented <emeyer> …If calc() resolves to a single value, you get that value without the calc() wrapped <emeyer> …clamp() resolves to the clamped value <emilio> q+ <astearns> ack emilio <emeyer> emilio: Want to clarify that I think the second example is wrong <emeyer> chris: Yes, you’re right; oops <emeyer> emilio: Otherwise seems fine to me <dbaron> I think 1/0 should be +inf, no? <emeyer> TabAtkins: This is fine with me <emeyer> astearns: Comments or objections? <TabAtkins> 1/0 is definitely inf <emilio> nvm <emeyer> (silence) <TabAtkins> https://drafts.csswg.org/css-values-4/#css-infinity <emeyer> RESOLVED: Accept the proposed resolution with the examples included |
I am sorry but, can you please clarify one last time if (simplified) math functions should appear in the serialization of specified non-sRGB color values?
edit: never mind, it is implied in 15.1. Serializing alpha values (ie. math functions should be preserved in non-sRGB color functions and the above WPT tests is wrong)
I hope it is fine if I add the corresponding tags for the following (in serialize a math function, I guess):
|
With the addition of more specificity for the specified value of colors that just went in (thanks @svgeesus!), one thing that I would like to be explicitly specified is whether calc() should be preserved through specified value serialization.
For example, take:
In Safari and Firefox (I have not tested anything else), this logs
rgb(100, 255, 255)
, seemingly resolving the calc(). (See https://bug-250325-attachments.webkit.org/attachment.cgi?id=464424 for a live test case). This is inconsistent with other properties (like say,width
), and the waycalc()
is specified (see #8290 (comment)).My proposal would be to have colors match other properties and perverse the minimal calc(). So, for the example above, I would expect the right serialization to be
rgb(calc(100), 255, 255)
.I can see some argument that legacy colors have had this behavior long enough and the required conversions from hsl() to rgb() would make the rules inconsistent in some places, so, as an alternative to always requiring preservation, I think requiring it for all non-legacy colors would be a good option as well.
The text was updated successfully, but these errors were encountered: