Repository navigation
Description
This is related to #633 and this part of css-fonts-4: https://drafts.csswg.org/css-fonts-4/#font-face-src-parsing
A bit late to the party, but I wondered: what if, instead of adding yet another microsyntax for feature detection, we use @supports with an appropriate font-technology() function (or whatever we want to name it)?
We recently resolved to allow nesting of conditional rules inside regular rules, so that authors can do things like:
a {
color: red;
@supports (foo: bar) {
color: green;
}
}What if this was allowed in @font-face as well? That way, authors could do something like:
@font-face {
font-family: Foo;
src: url("foo.woff2") format("woff2");
@supports font-technology(variations) and font-technology(COLR) and font-technology(palettes) {
src: url("foo.woff2") format(woff2);
}
}or
@font-face {
font-family: Foo;
src: url("foo.woff2") format("woff2");
@supports font-technology(variations COLR palettes) {
src: url("foo.woff2") format(woff2);
}
}instead of:
@font-face {
font-family: Foo;
src: url("foo.woff2") format("woff2");
src: url("foo.woff2") format(woff2 supports variations color(COLR) palettes); }Benefits:
- It reuses existing syntax, and can be extended to other types of rules in the future, if needed
- It skips the parsing weirdness for
srcthat this microsyntax has introduced - It can be used elsewhere, to allow authors to branch their styling differently based on whether these capabilities are allowed. I'd imagine loading a monochrome font over a color font, or a non-variable font would require a fair bit of style differentiation beyond which font is being loaded.
- It can be used in JS as well, through the existing
CSS.supports()API (current syntax also allows programmatic detectability but in a much clunkier way - Authors can decide which descriptors to vary, e.g. they may wish to give the color/variable font a different name
- Arguably easier to read. I find the current proposal quite hard to read, as everything in
format()is a list of keywords, with no hierarchy. Also, the syntax makes it unclear whether this is a feature query for the browser, or informing the browser what the font file supports.
Downsides:
- I'm hoping UAs can implement this as a one-off, without implementing CSS Nesting in its entirety. My understanding is the functionality is needed yesterday, so introducing a big blocker would not be desirable. Would appreciate thoughts from implementors here.
- More verbose
Unlike conditional rules in general, feature queries do not change during the lifetime of the page load, and thus this should not trigger re-interpretation of the @font-face rule or be more heavyweight in any other substantial way.
If such syntax is used with today's browsers, they drop the @supports rule but keep the @font-face rule, so it does appear forwards compatible. testcase
There are no implementations of the current syntax, so it may not be too late for the change.
Thoughts, @svgeesus @litherum @fantasai @tabatkins?
Activity
svgeesus commentedon Aug 16, 2021
This seems obvious but checking just in case: your proposal @LeaVerou is to allow
@supportsinside any at-rule that has descriptors (so, not@charsetfor example), not solely on@font-face, right?LeaVerou commentedon Aug 16, 2021
Currently it is for
@font-face. Obviously, it would be better to allow it in every at-rule, but I didn't want some unlikely combination of at-rule and@supportsto hold up this proposal, so I figured we could start small and expand as use cases arise.drott commentedon Aug 20, 2021
CC @jfkthame
I'll investigate what that would entail from an implementation point of view (complexity, overhead) and comment once I have some findings.
One consideration from a readability point of view: If we introduce such a
@supportsrule, we will have both mechanisms: a list of entries in thesrc:descriptor (for example multipleurl()entries potentially then "legacy"format("...")specifiers (with its own semantics of choosing the first compatible one from this list) and potentially multiplesrc:descriptors conditional on@supportsblocks in the same@font-facerule, which I personally do not find great for consistency or readability. In other words, we would change the primary paradigm forsrc:selection to the@supportssyntax but would still need to keep compatibility with the current approach of traversing a list of entries.FWIW, the "parsing weirdness" may be considered addressed or improved with the most recent change which references the CSS syntax spec for parsing a comma separated list of components.
emilio commentedon Aug 20, 2021
How is the supports rule represented in the OM? Implementation-wise I think it'd be easier for us if it just disappeared, but...
LeaVerou commentedon Aug 20, 2021
Hi @drott!
Yeah, this was raised by @plinss as well. The counter-argument he agreed to was that
@supportscame afterformat(), so while we're stuck withformat()for legacy format selection, we shouldn't be actively developing two different feature detection mechanisms, one of which is entirely ad hoc and severely more limited.I was referring to the fact that this descriptor's syntax needs prose and cannot be fully described by a grammar. I wasn't even aware that it used to be even weirder, whoa!
@emilio
I've wondered about this too, but I'm afraid making it disappear would be fairly inconsistent with every other @-rule, which would be even more confusing once Nesting is implemented.
tabatkins commentedon Aug 20, 2021
While it would involve more duplication, would it be okay to just leverage @supports normally, with some new queries to ask about various font-feature support, and then just have @font-face as a child of the rule like normal?
The big argument against is if we think multiple independent queries affecting different bits would be common; you'd have a combinatorial explosion to achieve equivalent results.
tabatkins commentedon Aug 20, 2021
Looking at the proposal itself - it feels slightly weird to have context-specific @supports (I presume this wouldn't allow arbitrary property-support queries, but only font-based ones?). If I'm wrong about that and this would just be an ordinary @supports, with a supporting proposal to add the font-feature queries, then this is less weird. (If I'm right, naming it
@font-supportsor something would defuse my objection.)I don't have a strong opinion on whether this should be treated as a parse-time syntax, disappearing from the tree in the OM, or kept around like normal @supports is. Parse-time is definitely simpler overall, but I understand how it feels new and odd.
Overall tho, I definitely support something like this over the growing weird microsyntax. The microsyntax was reasonable when it was just one thing, but it's getting out of hand.
LeaVerou commentedon Aug 21, 2021
I think that could be a good first step, and would enable authors to do what they want with some duplication, and would likely (?) be relatively easy to implement. However, we do eventually want to avoid the duplication, even if multiple independent queries aren't common.
It is not context-specific. The whole idea is that this way authors can use it to feature detect in any context that suits them, not just to differentiate the
src, but possibly other aspects of their style.drott commentedon Aug 23, 2021
Having looked at and discussed with my CSS colleagues, the implementation of
@supportsinside the@font-faceat-rule would be a larger effort, in particular if the@supportsrules need to be represented in the CSSOM, which poses problems given the current internal representation. (In addition, we're blocked on some parser refactoring which would make this more difficult, but that's an internal issue).Yes, I agree, adding something similar to a
<supports-font-technology-fn>to 2. Extensions to the @supports rule with syntax similar to what is in the current font spec proposal is immediately useful for the desired feature detection throughCSS.supports()JavaScript and would immediately work at the top level (not nested).This would give us a path that's relatively straight-forward to implement and not blocked on nesting
@supportsinside@font-face, while it would still allow for that kind of nesting later and migrating away from unnecessary@font-facerepetition.LeaVerou commentedon Aug 23, 2021
I think adding the
@supportscriteria first, and implementing the nesting step later is a good path forwards.Adding this to the agenda so we can resolve that these changes have CSS WG consensus.
[css-conditional-4] Extend supports feature to express font capabilities
drott commentedon Aug 24, 2021
In this branch I drafted an edit to css-conditional-4, carrying over the syntax from fonts-4's - Parsing the source descriptor, an excerpt from that draft (feel free to comment on the commit directly as well):
Considerations:
<font-technology>in the<supports-font-technology-fn>rule as required combinations of technologies can be expressed throughandandorof the@supportssyntax, which I consider an improvement over the syntax in the fonts spec.I'd be very happy if in tomorrow's meeting we could attempt to resolve towards a direction of the syntax along those lines (feedback very welcome), in addition to the general aim to resolve adding the criteria to the
@supportsrule.77 remaining items
svgeesus commentedon Oct 21, 2021
Edits made to CSS Conditional 4, CSS Fonts 4, and CSS Fonts 5.
svgeesus commentedon Oct 21, 2021
Extensions to the @supports rule
Parsing the src descriptor (4)
and
Parsing the src descriptor (5)
Font formats
Font technologies
LeaVerou commentedon Oct 21, 2021
I thought we could get rid of the parsing weirdness around
srcnow?svgeesus commentedon Oct 21, 2021
We got rid of the weirdness around
format supports whatever. We still have a descriptor wchich is a comma-separated list of items, where each item is aurl()followed by an optionalformat()and an optionaltechnology()so we still need to describe how to work out the winning item.Support CSS Conditional 5 font feature detection extensions
Support CSS Conditional 5 font feature detection extensions
Support CSS Conditional 5 font feature detection extensions
Support CSS Conditional 5 font feature detection extensions
Support CSS Conditional 5 font feature detection extensions
Support CSS Conditional 5 font feature detection extensions
Bug 1789817 [wpt PR 35829] - Support CSS Conditional 5 font feature d…
Bug 1789817 [wpt PR 35829] - Support CSS Conditional 5 font feature d…
Bug 1789817 [wpt PR 35829] - Support CSS Conditional 5 font feature d…