Skip to content

feat: support physical dimension units (pt, mm, cm, in) for print/PDF design systems - #164

Open
SomSamantray wants to merge 5 commits into
google-labs-code:mainfrom
SomSamantray:feat/physical-dimension-units
Open

feat: support physical dimension units (pt, mm, cm, in) for print/PDF design systems#164
SomSamantray wants to merge 5 commits into
google-labs-code:mainfrom
SomSamantray:feat/physical-dimension-units

Conversation

@SomSamantray

Copy link
Copy Markdown

Summary

Widens the Dimension grammar from px/em/rem to also accept pt, mm, cm, in — the print-native units CSS already supports — so print/PDF-targeting DESIGN.md files (academic papers, book layouts, page.pdf()/WeasyPrint pipelines) can express normative values without lossy conversion.

Closes #162.

What's in here

  • Schema (spec-config.yaml): added pt, mm, cm, in to the units: list — the single source of truth re-exported as STANDARD_UNITS. No new print-specific category; per the issue, this is straightforward acceptance, not a new taxonomy.
  • De-duplication (model/handler.ts): the rounded and typography (fontSize/lineHeight/letterSpacing) blocks each hand-spelled a unit !== 'px' && unit !== 'rem' && unit !== 'em' literal check that bypassed the config entirely — widening the YAML alone would have updated the docs while the linter kept rejecting the new units. Both sites now check against a STANDARD_UNIT_SET derived from the same config, so there's one source of truth and the next unit addition only touches spec-config.yaml.
  • Removed a second duplicate: found while testing — spec-config.yaml's types.Dimension had its own hardcoded units: sub-list, stale and separate from the top-level list. Removed it so the doc renderer's existing fallback (config.STANDARD_UNITS) is the only path.
  • Docs: docs/spec.md regenerated via bun run spec:gen (never hand-edited); README's token-type table updated to match.

Review notes

A simplify pass caught a subtlety worth flagging: the first version of the handler.ts fix called the existing isStandardDimension(raw) helper, which re-parses the raw string internally — but both call sites already have the parsed dimension in hand (resolved/parsed) from a parseDimension() call one line earlier. Three independent review lenses (reuse, quality, efficiency) all flagged the same redundant re-parse; fixed by checking the already-parsed .unit against STANDARD_UNIT_SET directly instead.

Testing

  • bun test — 315 pass, 0 fail.
  • bunx tsc --noEmit clean.
  • bun run spec:gen --check confirms deterministic doc generation.
  • New tests cover: pt/mm/cm/in acceptance in both rounded and typography, non-standard units (vh) still rejected, and px/em/rem behavior unchanged.

🤖 Assisted by Compound Engineering

zachshallbetter added a commit to zachshallbetter/design.md that referenced this pull request Aug 11, 2026
Implemented support for axis-specific padding properties (paddingX and paddingY) inside component token definitions (resolves Issue google-labs-code#160).

* Background & Motivation:
  - By default, the linter and spec support a uniform 'padding' sub-token for components. However, asymmetric layouts (e.g. button rows or inputs with larger horizontal than vertical insets) are standard in production design systems. Adding 'paddingX' and 'paddingY' solves this gap natively.
  - This matches common framework models (Tailwind's px/py, SwiftUI, Flutter) and avoids nested layout complexity (such as the schemas discussed in Issue google-labs-code#17).
  - This aligns with the philosophy of PR google-labs-code#89 (avoiding CSS property bloat like paddingLeft/paddingTop) by introducing structural layout minimums rather than exhaustive box-model properties.
  - Sourced independently from PR google-labs-code#164 to prevent merge conflicts.

* Changes:
  - Add 'paddingX' and 'paddingY' to component_sub_tokens list in spec-config.yaml.
  - Update the valid component properties list in README.md.
  - Regenerate docs/spec.md using the compiler script.

* Test Coverage:
  - Add validation tests in broken-ref.test.ts to verify that components using paddingX and paddingY do not trigger unrecognized sub-token warnings.
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.

Dimension units: support physical units (pt, mm, cm, in) for print/PDF design systems

1 participant