measureElement
import { createElement, measureElement, Rectangle, type CanvasMeasurementService, type Constraints,} from "@pibbl/core";measureElement(element, constraints, service) measures one element through
its opt-in primitive capability. It is pure: it cannot render or acquire
runtime resources. Components without a measure capability return an
unsupported result, and cyclic measurement dependencies are rejected.
Signal writes are rejected throughout measurement, including custom normalization, measurement callbacks and the text-measurement service. This also applies when called outside a mounted component. A rejected signal update does not run its updater or change its value; ordinary writes remain available after measurement returns or throws.
const element = createElement(Rectangle, { style: { width: 120, height: 60, fill: "#2563eb" },});const constraints: Constraints = { minWidth: 0, maxWidth: 240, minHeight: 0, maxHeight: 120,};const measurementService: CanvasMeasurementService = { measureText: () => ({}) as TextMetrics,};const result = measureElement(element, constraints, measurementService);Constraints and a CanvasMeasurementService describe the call; its result is a MeasureResult. Use declared boxes for ordinary layout rather than assuming visual primitives
have intrinsic dimensions.
In the default native layout engine, an omitted/automatic-width LTR, unwrapped
Flex can use equal finite minWidth and maxWidth as an exact row width.
Definite-main, declared-cross children can then resolve percentage minWidth and
maxWidth; the result has that exact width and its natural cross size. Exact
zero is valid. A maximum alone or unbounded availability does not supply a
percentage basis. Other intrinsic measurement restrictions still apply.
The column counterpart uses equal finite minHeight and maxHeight for an
omitted/automatic-height LTR, unwrapped Flex. Direct percentage height bounds
resolve against that height; the result retains its natural width. A maximum
alone remains an availability limit. These are single-main-axis admissions;
they do not define cyclic percentage sizing or a new both-axes-exact shortcut.
The custom intrinsic leaf example uses this existing operation inside a paired provider, then renders the same percentage-capped row with matching pointer targets.
API details from source
Section titled “API details from source”
Measures an element against logical size constraints using the supplied Canvas measurement service.
measureElement: (element: PibblElement<any>, constraints: Readonly<Constraints>, service: CanvasMeasurementService) => MeasureResultRelated API: measureElement, PibblElement, Constraints, CanvasMeasurementService, MeasureResult.
Parameters
Section titled “Parameters”-
element— Element whose declared measurement capability is used. See PibblElement. -
constraints— Available size constraints in logical units. See Constraints. -
service— Canvas text measurement service. See CanvasMeasurementService.
Returns
Section titled “Returns”Measured dimensions, or an unsupported result with its reason. See MeasureResult .
See also
Section titled “See also”View source — packages/core/src/lib/layout/measure.ts:62
Implementation guidance for agents
Section titled “Implementation guidance for agents”Read the Drawing, layout, and effects companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.
Complete minimal examples
Section titled “Complete minimal examples”- Intrinsic measurement: Measure a Text element with a Canvas service and display its computed dimensions. Plain source
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.