feat(text): verticalAlign works without maxHeight (flex-friendly)#29
Merged
Conversation
verticalAlign previously required maxHeight to be set — useless when a
flex parent (or the user) grows the text node's `h` beyond the intrinsic
text height. Switch the alignment math to compare against the intrinsic
text height (`_renderInfo.height`), using `maxHeight` if set and falling
back to the node's own `h` otherwise.
This also fixes a subtle bug in the original formula: `maxHeight - h`
was wrong when `h` had been modified post-load (e.g., by flex), because
`h` no longer equaled intrinsic height. The new formula uses
`intrinsicH` explicitly.
Adds a VRT row ("Explicit h, no maxHeight") that creates a text node,
awaits load, then sets `node.h = 200` to exercise the new path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builds on #28. After that PR,
verticalAlignactivated whenevermaxHeight > 0. This change goes further:verticalAlignnow activates whenever the containing box is taller than the intrinsic text height — even withoutmaxHeight. The "containing box" ismaxHeightif set, otherwise the node's ownh(which a flex parent or the user may have grown).This makes
verticalAlignJust Work inside flex layouts:Each text's caps land dead-center inside the 300px row, with no
maxHeightboilerplate.Implementation
src/core/CoreTextNode.ts:152-161 — switched the slack formula from
maxHeight - hto(maxHeight ?? h) - intrinsicH, whereintrinsicH = this._renderInfo.height:This also fixes a subtle bug in the original formula:
maxHeight - hwas wrong whenhhad been modified post-load (e.g., by flex), becausehno longer equaled the intrinsic text height. The new formula usesintrinsicHexplicitly.Other changes
verticalAligndocstring updated to describe the new activation rule.node.h = 200to exercise the new code path.Test plan
pnpm buildclean.vitest run— 182/182 pass.text-vertical-align-*.png) — will be done before merge. Only the text-vertical-align snapshots are expected to change (added one row); other tests don't growhpast intrinsic without also settingmaxHeight.🤖 Generated with Claude Code