Text and expressions
What an attribute’s text becomes: rich text and its footnotes, live values, symbol names, measured and wrapped labels, and a compiled expression.
@internote/canvas-sdkOn this page
An author's text is rarely plain: a label can hold bold, links, maths, symbols and live values. This area covers what that text becomes, and the maths behind expressions.
Rich text. renderRichText draws inline content as React nodes. flatten turns it back into a plain string, for alt text or measuring.
Live values. When an author writes {{#f.slope}}, prose shows a number the canvas computed. LiveValueStore holds those numbers: an environment publishes to it, and the text reads from it.
Measuring labels. textWidth, wrapWidths and balancedWrap measure and wrap a label before it is drawn, so it can be placed where it fits.
Expressions. evaluateExpression evaluates an author's maths safely, with parameter values injected. compileSafeExpression compiles one to a function once, for code that samples it thousands of times. compileComplexExpression and evaluateComplexExpression do the same for complex numbers.