@mocanvas/mocanvas · class
declare class TextMeasureMeasures runs of text with a hidden DOM element, mirroring the CSS the
<TextLabel> component uses (pre-wrap + break-word, border-box padding).
Falls back to estimateTextSize where no document exists (tests, SSR).
measureHtml measures a rich-text label the same way, from the HTML
renderHtmlFromRichTextForMeasurement produces. Both paths share the cache
and the probe element, so a rich-text label and the plain-text label it
flattens to are measured by the same code.
Methods · 6
get cacheSize(): numberNumber of cached measurements (for tests and debugging).
clearCache(): voiddispose(): voidmeasureHtml(html: string, opts: TextMeasureHtmlOptions): TextHtmlMeasurementMeasure a run of HTML — a rich-text label — laid out the way the DOM overlay renders it.
Only pass HTML this package generated (richTextToHtml escapes text and
scheme-checks link hrefs); the probe is inert but it is still a live DOM
subtree.
measureHtmlBatch(items: readonly {Measure several HTML runs against one probe. Nothing is shared between the items beyond the element itself; the win is one style write and one layout flush per item instead of one per call site.
measureText(text: string, opts: TextMeasureOptions): TextMeasurementmocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.