@motion-script/core / MeasureScope
Abstract Class: MeasureScope
Defined in: render/measure-scope.ts:17
Provides text-measurement primitives to any context that needs to know how wide a run of text will be before actually drawing it (e.g. for layout calculations, line-breaking, or positioning).
RenderContext implements this interface so nodes can measure text through
the same object they use to draw — no separate measurement pass needed.
Extended by
Constructors
Constructor
new MeasureScope():
MeasureScope
Returns
MeasureScope
Methods
layoutTextBlock()
layoutTextBlock(
state):TextBlockLayout|null
Defined in: render/measure-scope.ts:59
Lay state out the way it would be drawn and report where every character
landed — see TextBlockLayout for the space and the caret model.
This is what makes on-canvas text editing possible: glyph positions live in the backend's shaper, so a host drawing its own caret and selection has no way to compute them, and anything it approximates in the DOM disagrees with the render as soon as the font, the line height or the wrapping does.
Takes the whole TextState rather than a handful of font fields
because the resolution a caret has to agree with lives in the backend:
'autofit' picks a size from the box, wrap turns the width into a wrap
limit, and textAlign places the lines within it. Handing over the same
descriptor that gets drawn is what keeps the two from drifting apart.
Returns null when the backend can't measure this — the default, so a
backend that never needed glyph positions keeps working, and for cases no
caret model fits: text-on-path (glyphs follow a curve, not a line box) and
a block with active selection segments.
Parameters
state
Partial<TextState>
Returns
TextBlockLayout | null
measureText()
abstractmeasureText(text,fontSize,fontFamily,fontWeight?,letterSpacing?,fontStyle?):number
Defined in: render/measure-scope.ts:30
Returns the advance width (in pixels) of text rendered at the given
fontSize with the specified font properties.
Parameters
text
string
The string to measure.
fontSize
number
Size in pixels.
fontFamily
string
CSS-style family name (e.g. "Inter").
fontWeight?
number
Numeric weight (100–900). Defaults to 400 when omitted.
letterSpacing?
number
Extra inter-glyph spacing in pixels. Defaults to 0.
fontStyle?
Italic / oblique variant. Defaults to normal.
Returns
number
Advance width in pixels.