Skip to content

feat: typography CSS keywords - #822

Open
unpunnyfuns wants to merge 2 commits into
terrazzoapp:mainfrom
unpunnyfuns:feat/typography-css-keywords
Open

feat: typography CSS keywords#822
unpunnyfuns wants to merge 2 commits into
terrazzoapp:mainfrom
unpunnyfuns:feat/typography-css-keywords

Conversation

@unpunnyfuns

Copy link
Copy Markdown
Contributor

Changes

line-height: normal and letter-spacing: normal have 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 string to both slots in the typography sub-value type map, matching the carve-out paragraphSpacing and wordSpacing already have, and skips core/valid-number / core/valid-dimension for an allowlist: normal plus the five CSS-wide keywords.

Depends on #821, without it these keywords reach transformDimension and emit undefinedundefined. Shows two commits until that merges; the first is #821.

How to Review

  • keywords.ts is the whole design. normal + initial | inherit | unset | revert | revert-layer (css-cascade-5 §defaulting-keywords). normal is the only property-specific keyword for either property.
  • The rest is two guard calls and one line in the type map.

pnpm --filter @terrazzo/parser test: 2 new cases.

@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4671c2b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@terrazzo/parser Major
@terrazzo/token-tools Major
@terrazzo/plugin-css-in-js Major
@terrazzo/plugin-css Major
@terrazzo/plugin-js Major
@terrazzo/plugin-sass Major
@terrazzo/plugin-swift Major
@terrazzo/plugin-tailwind Major
@terrazzo/plugin-token-listing Major
@terrazzo/plugin-vanilla-extract Major
@terrazzo/cli Major
@terrazzo/token-types Major
@terrazzo/use-color Patch

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

@unpunnyfuns
unpunnyfuns force-pushed the feat/typography-css-keywords branch from e04ed0b to 4671c2b Compare August 12, 2026 18:32
@unpunnyfuns

Copy link
Copy Markdown
Contributor Author

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?

@Sidnioulz

Copy link
Copy Markdown
Collaborator

@drwpow for context, I brought up to @unpunnyfuns that in Swatchbook, we'd like to show normal when the CSS platform value is normal. This isn't quite the same as making it available directly at the parser level though. I think this PR could be a nice QoL deviation from the spec, but it could also be unwanted. I haven't taken the time to properly think about the implications of my ask, so there may need to be a discussion between us 3.

@unpunnyfuns

Copy link
Copy Markdown
Contributor Author

I concur, this is more a QoL, and would stray from the narrow path.

@drwpow drwpow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line-height: normal and letter-spacing: normal have no numeric form, both resolve from font metrics

My understanding is somewhat different, more aligning from MDN:

normal

Depends 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:

  1. core/valid-typography: add a allowCSSKeywords option, and document that this allows any CSS-valid keyword for lineHeight and letterSpacing. It should default to false
  2. Remove the changes from valid-dimension.ts and valid-number.ts, and instead, add the bypass only in valid-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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants