fix(editor): resolve theme font sizes against the parent size

Draft
DA
2d ago
+384-14

Related issue or discussion

Internal report, MES-3088: theme text sizes in the editor do not render at the size typed.

What this changes

Theme font sizes are typed in px and compiled to em. Every size was divided by a fixed 14, not by the size of the element it sits in, so the result depended on the base Text size and on nesting. With Text 15, a Title of 15 rendered at 16.07px and a Title of 14 rendered at 15px.

Sizes still compile to em. What changed is the divisor:

  • Base Text size: unchanged, Text / 14 em, relative to the mail client's default.
  • Explicit component size: size / parent size em. The parent is the base Text size, except list item → list and nested list → list item.
  • Unset sizes: untouched, so the theme ratios (for example Title 2.25em) keep scaling with the base.

With Text 15, Title 15 now compiles to 1em and Title 14 to 14/15 em.

Canvas and email parity for lists:

  • The canvas applied the paragraph rule to paragraphs inside list items and the list rule to nested lists. The serializer applies neither, so sizes compounded on the canvas only. The canvas selectors now match the serializer. Email output is not changed by this part.
  • A Code Block size was multiplied by the inner code tag's 0.92em on the canvas only; that tag now gets 1em when the block has an explicit size.

stylesToCss now calls getMergedCssJs instead of repeating it. No public signature changed.

Behaviour change to review

With the default Text size (14), output is identical to before except for the list chain: a List item size under an explicit List size, and a Nested list size under an explicit List item size, now divide by that parent instead of 14. Saved themes that set both will render those at the typed size, which differs from what they render today.

Known limit

Links, inline code, and list items under a nested list resolve against one static parent, so mixed explicit sizes there can still compound. Noted in a shortcut: comment.

Tests

  • Table test for the resolved em values on Basic and Minimal.
  • Browser spec comparing the computed canvas font size per node with what the serializer returns for a paragraph, a list and a nested list.
  • Unit tests, browser tests, typecheck and lint pass locally.

Checklist

  • I understand the code in this PR and the problem it solves.
  • I read this description, and it accurately describes the change.
  • I added a changeset, or this change doesn't affect a published package.

Generated by Claude Code


Summary by cubic

Fixes editor theme font sizes so typed px sizes render at the size typed. Sizes compile to em but were divided by a fixed 14px; they now divide by the parent element's effective size, so a Title under 15px Text renders at 15px, a list item resolves against the list size, and a nested list against the list item size. The canvas selectors now match the serializer so paragraph, list, and code block sizes no longer compound, and stylesToCss delegates to getMergedCssJs.

With the default 14px Text, email output is unchanged except for saved themes that set a size on both a list and its list item, or a list item and its nested list; those now render at the typed size.