// Normal mode (collapse spaces and newlines)
const normalText = new Text({
text: 'Hello World\n\nNew Line',
style: {
whiteSpace: 'normal',
fontSize: 24
}
}); // Renders as: "Hello World New Line"
// Pre mode (preserve all whitespace)
const preText = new Text({
text: 'Hello World\n\nNew Line',
style: {
whiteSpace: 'pre',
fontSize: 24
}
}); // Preserves spaces and line breaks exactly
// Pre-line mode (preserve newlines, collapse spaces)
const preLineText = new Text({
text: 'Hello World\n\nNew Line',
style: {
whiteSpace: 'pre-line',
fontSize: 24
}
}); // Preserves line breaks, collapses multiple spaces
// With word wrap enabled
const wrappedText = new Text({
text: 'A long text with multiple spaces\nand line breaks',
style: {
whiteSpace: 'pre-line',
wordWrap: true,
wordWrapWidth: 200,
fontSize: 24
}
});
Supported values:
Controls how whitespace (spaces, tabs, and line breaks) is handled within the text. This affects text wrapping and spacing behavior.