Open LeaVerou opened 5 months ago
Committed a first pass at the generic <boolean>
grammar
Committed a first pass at the generic
<boolean>
grammar
Thanks! I think the ergonomics will become more clear once we edit specs to reference it too.
Btw if we call it <boolean>
that sort of implies we also have constants like true
and false
. If we don’t want that, perhaps <condition>
is more clear.
Can you please tell me if you plan to use context-sensitive production notations?
<@media/bool-test> = <media-feature>
<@supports/bool-test> = <supports-feature>
<rgb()/calc-keyword> = r | g | b | alpha | <calc-constant-keyword>
<width/intrinsic-size-keyword> = auto | min-content | max-content
Maybe the form should be @media <bool-test> = <media-feature>
because I am not sure how to annotate <context> <type> = value
using the above form.
A CSS parser would need to look for the closest production, ie. <local><type>
has priority over (global) <type>
.
I do not know if <dfn for="@foo"><type></dfn> = value
would be equivalent to <dfn><@rule/type></dfn> = value
.
@tabatkins and I drafted up a <<boolean [ test ]>>
multiplier type into css-values-5. We think this covers the use cases pretty well, and should hopefully be reasonably easy to understand. See https://drafts.csswg.org/css-values-5/#boolean Agenda+ to review with the CSSWG.
Perhaps syntax attribute names should be considered, noting that authors can now specify a value including a <syntax>
. For example, <number range=[0,∞] unit=px>
and <boolean from=[<test>]
or similar.
The CSS Working Group just discussed [css-values-4][Editorial] `<condition>` type that other specs reference
, and agreed to the following:
RESOLVED: Add <boolean-expr[...]> as a value definition syntax function multiplying its argument into a boolean expression microsyntax
So https://github.com/w3c/csswg-drafts/labels/Needs%20Edits is removed (for values 5) but the specs listed at the top of the issue still all need to be edited.
This came up when I went to implement the resolution from #10064 and spec my
if()
proposal.Currently, we have several specs using one or more types of conditionals, and in every case, this is defined inline. This means the boolean operators (
and
,or
,not
) are also defined inline, which is awkward, error-prone, and easy to forget.Some examples:
Media Queries 5:
@supports
:CSS Conditional 4 adds…:
CSS Conditional 5 adds…:
@container
:@import
:Tab’s
@when
proposal:In fact, there is an inline issue right there proposing a lighter form of what I’m arguing for here:
Proposal
I propose we introduce a new
<boolean>
or<condition>
value type that other specs can reference. It will include both the grammar for the boolean algebra, as well as bare and functional forms for each conditional. Each conditional type should also include metadata like:Not all condition types need to be defined in values, we could extend the
<condition>
token in other specs, as we often do with value types. E.g. size queries may be a better fit in css-contain, since they are not valid anywhere else.The prose should explain that specs using
<condition>
should specify:To make this more concrete, this is the state of the current specs with conditionals with this framing:
supports()
media()
size()
style()
@container
@supports
@media
@import
if()
@if
/@when
While this change is editorial, I think it will pave the way for a lot of quick DX wins involving mixing and matching conditions (e.g.
supports()
in@media
.It could also allow creating JS APIs that handle conditions generically, avoiding the current issue of e.g. having
matchMedia()
for media queries, but no way to detect when a container query matches or not.