">
> <style> @media (min-aspect-ratio: 1 / 1) { } @media (min-aspect-ratio: calc(1) / calc(1)) { } style> <script> alert(document.styleSheets[0].cssRules[0].cssText) alert(document.styleSheets[0].cssRules[1].cssText) script>
The text was updated successfully, but these errors were encountered:
Based on the resolution of #434, I think we should do the same here, and simplify (and clamp, if necessary) early. However, there's one part of the resolution I don't understand, which was highlighted by @tabatkins in that discussion: we simplify and clamp early, but then we put a calc() around the result of the simplification. If we apply the same logic to media queries, this means that I am not sure I follow why. @tabatkins can you explain? |
FWIW that's what currently Firefox implements for normal declaration blocks / computed values. That is: >
<style>
#foo { line-height: calc(1 + 3); }
style>
<script>
alert(document.styleSheets[0].cssRules[0].cssText)
script> Alerts For media queries I didn't know whether we should do that or not, because it's not clear whether it's a computed or a specified value (thus this issue). |
@tabatkins ping |
Yeah, the resolution ended up what in what I think is the best situation - simplify/clamp as early as possible. In MQs, that's always possible, since the allowed relative units can be absolutized immediately. We retain the calc() wrapper so that the value keeps the same "shape", particularly in TypedOM. |
That's the part I'm not 100% I understand the benefit of, but alright. |
For the two browsers that currently implement this (Firefox and WebKit), both examples above serialize to |
That sounds worth bring back to the WG. Agenda+ |
Does WebKit actually ship this? https://bugs.webkit.org/show_bug.cgi?id=181716 was resolved two days ago. |
My definition of ship may have been a bit loose; it should be in the next Safari TP. (It should also be noted that I was the implementer there) |
Now I look at it, FF still doesn't ship this (it'll be on FF59), but will soon (it's the next release).
I'm not sure we should convert relative units to absolute units (even though it's doable, and in fact trivial). That'd be inconsistent with how every browser serializes something like: @media (min-width: 10em) {} (which preserves the unit). In any case, the following: @media (min-width: calc(1em + 10px)) {} Should serialize either as Firefox right now preserves the specified value as-is, which is kind of inconsistent with what we do for numbers, because That's an artifact of how it was implemented and I'm happy to make whatever change the WG decides is sane :) |
@emilio WebKit serializes that as |
Thanks! That matches Firefox as of right now. Also just realized that we can't just absolutize the lenghts, because the initial font size used for |
It seems like dropping This means, I think (but maybe I'm wrong??), that: @media (aspect-ratio: calc(-1) / calc(-1)) { ... } is syntactically valid, but if it were serialized as: @media (aspect-ratio: -1 / -1) { ... } then that would be an invalid media feature value, which when reparsed and serialized again would produce: @media not all { ... } This breaks two of the fundamental principles of serialization (always serialize to valid syntax, serialize to something that when reparsed will serialize to the same thing). |
At least Firefox and WebKit (I suspect Blink too), serialize directly to: @media not all { ... } Which means that the rule is invalid at parse time. That's probably ok, but it's definitely observable. IIUC, clamping after parsing would involve evaluating that media query as if it was |
The Working Group just discussed The full IRC log of that discussion |
The Working Group just discussed
The full IRC log of that discussion |
The spec is now clear that math functions are simplified immediately at parse time as much as possible, then again at computed/used value time (which isn't relevant for MQs). Since MQs can convert all units to their canonical one, this means that all math functions in MQs should be resolvable immediately upon parsing. Serialization is clear that fully-collapsed calc()s only serialize as their argument (without the Note that, as currently specified, non-calc() math functions do not disappear if they're top-level even if they can be fully resolved; they retain their identify as the specific function and simplify their arguments. So a Since this should all be answered in the spec, I'm closing this issue. Feel free to reopen if there are any issues or confusing bits. |
@tabatkins so do the new calc() changes mean that stuff like |
That's a behavior change, it'd be nice to have tests for it. |
(Deleted previous comment, I misread.) Yes, it does mean that, but also, that's been the documented behavior for a good while; it's not a new consequence of my edits. I can go dig up the resolution covering it if you'd like. (See https://drafts.csswg.org/date/2019-09-21T18:35:38/css-values-4/#calc-serialize for this being present before my latest round of edits; the original change that added this is four years old.) |
OR WAIT DANG IT I STILL MISREAD No, |
Ok, that seemed to conflict with your quote above abut "math functions are simplified immediately at parse time as much as possible". I was reading that as "calc() can go away too if possible" (that's a simplification we do at computed-value time). https://drafts.csswg.org/css-values-4/#calc-computed-value seems to imply that is a valid simplification. It'd be nice to clarify in the spec that dropping calc() at parse time is not a valid simplification. |
"Simplified" doesn't have a technical meaning. ^_^ I'm a little confused - you're linking to the text about computed value, but implying it says something about specified value? The "calc() wrapper goes away" isn't even specified in that section, it's part of serialization, and is clear about the condition that it occurs in. |
I was linking to the computed value section because it says:
Which to me seemed to imply that simplifying the computed value to a single numeric value (which I expect to mean "drops the calc from the internal representation") was also a valid part of the simplification algorithm referenced from that section. But if the calc going away is only meant to be a serialization tweak, not part of the simplification algorithm, that's good to know. No further questions spec-wise I guess... I assume then this is only observable from typed OM... Is that right? My reading of the spec says that |
TypedOM doesn't currently have the same "drop the wrapper" rules in its reification stuff, no. It might be better to be consistent there, tho? I don't have a strong preference either way, but I do like consistency when possible. |