feat: typography CSS keywords - #822
Conversation
🦋 Changeset detectedLatest commit: 4671c2b The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e04ed0b to
4671c2b
Compare
|
Torn between matching CSS properly and keeping it a simple pass. More keywords exist than the two covered here. Would a strict/loose option help? |
|
@drwpow for context, I brought up to @unpunnyfuns that in Swatchbook, we'd like to show |
|
I concur, this is more a QoL, and would stray from the narrow path. |
drwpow
left a comment
There was a problem hiding this comment.
line-height: normalandletter-spacing: normalhave no numeric form, both resolve from font metrics
My understanding is somewhat different, more aligning from MDN:
normalDepends on the user agent. Desktop browsers (including Firefox) use a default value of roughly 1.2, depending on the element's font-family.
In my testing this is true—Firefox and Chrome seem to be 1.2, while Safari is ~1.1. The CSS spec seems to provide a rough calculation that user agents may not implement. And I’m not sure there’s an equivalent for native code.
The goal of DTCG is to encourage token values be universal and not CSS-first. But all that said, I’m not opposed to this addition so long as it’s opt-in for users. So I’d like to request 2 things:
- core/valid-typography: add a
allowCSSKeywordsoption, and document that this allows any CSS-valid keyword forlineHeightandletterSpacing. It should default tofalse - Remove the changes from
valid-dimension.tsandvalid-number.ts, and instead, add the bypass only invalid-typography.ts. This is more extensible and can prevent future bugs, by not introducing the idea that simple types are “aware” of their parent composite types
With both of these changes I’d be happy to accept this 🙂
Changes
line-height: normalandletter-spacing: normalhave no numeric form, both resolve from font metrics, so neither can be written as a ratio or a length.Today there's no way to express them in DTCG.
Adds
stringto both slots in the typography sub-value type map, matching the carve-outparagraphSpacingandwordSpacingalready have, and skipscore/valid-number/core/valid-dimensionfor an allowlist:normalplus the five CSS-wide keywords.Depends on #821, without it these keywords reach
transformDimensionand emitundefinedundefined. Shows two commits until that merges; the first is #821.How to Review
keywords.tsis the whole design.normal+initial | inherit | unset | revert | revert-layer(css-cascade-5 §defaulting-keywords).normalis the only property-specific keyword for either property.pnpm --filter @terrazzo/parser test: 2 new cases.