Skip to contentBlack Friday: Framescript for €79 instead of €99 with the code BF2026

Reference: framescript/text

What a scene imports from framescript/text and calls, in the order the module exports it. Each entry has its signature, what it does, and the examples that use it; the types its signatures name are at the end.

Explained in Text, Layout.

buildLine

TypeScript
function buildLine(
  content: string,
  options?: BuildLineOptions
): BuildLine

A line of a few words that builds from the middle, one word a beat, in the look's own way. Add it, then play enter(), hold(seconds) and exit().

  • content: The words.
  • options: The look, the way the words arrive, an accent word, the beat, the size and the widest the line may be.
  • Returns: The line, to pass to add.

Examples: text/build-line

text

TypeScript
function text(content: string, style?: TextStyle): TextObject

Makes a text object to pass to add. Its layout is computed while add waits, which takes no scene time; after that chars, words, lines, width and height can be used. Content and style do not change later: make another text instead.

  • content: The text. \n starts a new line.
  • style: Font, size, colour and layout.
  • Returns: The text object.

Examples: text-reveals/typewriter, text/captions, text/rise-lines

column

TypeScript
function column(
  children: ReadonlyArray<Object3D>,
  options?: StackOptions
): Stack

Lays objects out from top to bottom. The column's origin is its top left corner.

  • children: The objects, in order.
  • options: gap, padding and align.
  • Returns: The column, to pass to add.

Examples: layout/stacks

row

TypeScript
function row(
  children: ReadonlyArray<Object3D>,
  options?: StackOptions
): Stack

Lays objects out from left to right. The row's origin is its top left corner. Text among the children is measured once it is ready, anything else by its bounding box.

  • children: The objects, in order.
  • options: gap, padding, align, and wrap with maxWidth.
  • Returns: The row, to pass to add.

Examples: layout/stacks

flipbook

TypeScript
function flipbook(
  contents: ReadonlyArray<string>,
  style?: TextStyle
): Flipbook

Makes a text that can change during a scene: one text per content, of which flip shows one at a time. Use count or scramble to make the contents.

  • contents: The contents to switch between, in order.
  • style: The style every content is set in.
  • Returns: The flipbook, showing its first content.

Examples: presets/flip, text-reveals/scramble, layout/flipbook

counter

TypeScript
function counter(value: number, options?: CounterOptions): CounterObject

Makes a number that counts: tween(total, { value: 128 }, 1.2), or countTo(total, 128). It is written with a fixed number of decimals, with separators between thousands, and with text before and after.

  • value: The number to start at.
  • options: { decimals, thousands, point, prefix, suffix, align, digits } and the text's style.
  • Returns: The counter, to pass to add.

Examples: text/counter

Types

BuildLine

TypeScript
class BuildLine extends PieceObject {
  /** The line's text; its words arrive one by one. */
  readonly text: TextObject
  /** How its words arrive. */
  readonly variant: BuildVariant
  /** Seconds between one word and the next. */
  readonly beat: number
  private readonly slide
  private readonly size
  private readonly maxWidth
  private fit
  /**
   * @param content - The words.
   * @param options - The look, the way the words arrive, an accent word,
   *   the beat, the size and the widest the line may be.
   */
  constructor(content: string, options?: BuildLineOptions)
  protected arrange(): void
  private centerOf
  private startX
  private hidden
  protected reset(): Step<unknown>
  private wordIn
  private slideTo
  protected arrive(move: Move): Step<unknown>
  /**
   * The line breathing while it stays: it grows a little in the push
   * variant and drifts up a little in the others.
   *
   * @param seconds - How long it stays.
   * @returns The step.
   */
  hold(seconds: number): Step<unknown>
  protected depart(move: Move): Step<unknown>
}

BuildLineOptions

TypeScript
interface BuildLineOptions {
  /** The look it is drawn in, the kit's when left out. */
  readonly look?: Look
  /** How its words arrive; the look's own way when left out. */
  readonly variant?: BuildVariant
  /** A word written in the look's accent. */
  readonly accentWord?: string
  /** Seconds between one word and the next; the variant's when left out. */
  readonly beat?: number
  /** The size of type: a role of the look or a size in world units. */
  readonly size?: TypeRole | number
  /** The widest the line may be, in world units; 12 when left out. */
  readonly maxWidth?: number
}

BuildVariant

TypeScript
type BuildVariant =
  | "rise"
  | "push"
  | "light"
  | "edge"
  | "depth"
  | "type"
  | "float"

CounterObject

TypeScript
class CounterObject extends Group {
  /** The number shown. */
  value: number
  private readonly decimals
  private readonly thousands
  private readonly point
  private readonly prefix
  private readonly suffix
  private readonly align
  private readonly alphabet
  private readonly slots
  private readonly inner
  private arranged
  private shown
  private readonly advance
  private left
  /**
   * @param value - The number to start at.
   * @param options - The format and the text's style.
   */
  constructor(value: number, options?: CounterOptions)
  /**
   * The value as it is written.
   *
   * @returns The text, such as `"$1,280.50"` or `"-$40.00"`.
   */
  get written(): string
  /**
   * Readies the text inside.
   *
   * @returns Nothing when the counter is ready now; otherwise a promise
   *   that resolves when calling again will make it so.
   */
  framescriptReady(): Promise<void> | undefined
  private measure
  /**
   * What the preparation before a draw writes besides this object's own
   * drawing: the parts of its digits, their opacity and place, which a
   * player then writes again on every frame where a track holds them.
   *
   * @returns The parts and their positions.
   */
  framescriptDrawWrites(): ReadonlyArray<object>
  /**
   * Shows the value as it is now. Whatever draws the scene calls this
   * after the timeline's values were applied and before it renders.
   */
  framescriptBeforeDraw(): void
  /**
   * The characters that are showing, for whatever wants to animate them.
   *
   * @returns The parts, from left to right.
   */
  get showing(): Array<TextPart>
}

CounterOptions

TypeScript
interface CounterOptions extends TextStyle {
  /** How many decimals to show. Defaults to 0. */
  readonly decimals?: number
  /**
   * What stands between every three digits before the point. Defaults to
   * `","`; an empty text leaves them together.
   */
  readonly thousands?: string
  /** What stands for the decimal point. Defaults to `"."`. */
  readonly point?: string
  /** Text before the number, such as `"$"`. */
  readonly prefix?: string
  /** Text after the number, such as `"%"` or `" ms"`. */
  readonly suffix?: string
  /**
   * Which end of the number stays where the counter is: `"left"`,
   * `"center"` or `"right"`. Defaults to `"left"`.
   */
  readonly align?: "left" | "center" | "right"
  /** The most digits before the point it can show. Defaults to 9. */
  readonly digits?: number
}

Flipbook

TypeScript
class Flipbook extends Group {
  /** One text per content, in order. Only one is shown at a time. */
  readonly frames: ReadonlyArray<TextObject>
  /**
   * @param contents - The contents to switch between, in order.
   * @param style - The style every content is set in.
   */
  constructor(contents: ReadonlyArray<string>, style?: TextStyle)
  /**
   * Lays out every frame, which `add` waits for.
   *
   * @returns A promise while any frame is being laid out, otherwise
   *   `undefined`.
   */
  framescriptReady(): Promise<void> | undefined
}

Stack

TypeScript
class Stack extends Group {
  /** The width after layout, padding included. */
  width: number
  /** The height after layout, padding included. */
  height: number
  /** Whether children follow to the right or downwards. */
  readonly direction: "row" | "column"
  /** Spacing, alignment and wrapping. */
  readonly options: StackOptions
  /**
   * @param direction - Whether children follow to the right or downwards.
   * @param children - The objects to lay out, in order.
   * @param options - Spacing, alignment and wrapping.
   */
  constructor(
    direction: "row" | "column",
    children: ReadonlyArray<Object3D>,
    options?: StackOptions
  )
  /**
   * Readies the children that need it, such as text, and then lays them
   * out. `add` waits for this.
   *
   * @returns Nothing when the layout is done now; otherwise a promise that
   *   resolves when it is, or when calling again will make it so.
   */
  framescriptReady(): Promise<void> | undefined
  /**
   * Measures the children and positions them. Call it again after changing
   * the children by hand; it moves them back to their places.
   */
  layout(): void
}

StackOptions

TypeScript
interface StackOptions {
  /** The space between neighbouring children. Defaults to 0. */
  readonly gap?: number
  /** The space between the edge and the children. Defaults to 0. */
  readonly padding?: number
  /**
   * Where a child sits across the direction: a row's `"start"` is the top, a
   * column's the left. Defaults to `"start"`.
   */
  readonly align?: "start" | "center" | "end"
  /** Whether a row continues on a new line at `maxWidth`. Rows only. */
  readonly wrap?: boolean
  /** The widest a wrapping row may get, padding included. */
  readonly maxWidth?: number
  /** The least width of the whole, padding included. */
  readonly width?: number
  /** The least height of the whole, padding included. */
  readonly height?: number
}

TextObject

TypeScript
class TextObject extends TroikaText {
  private last
  /** Every visible character, in reading order. White space has none. */
  chars: Array<TextPart>
  /** Every word, in reading order. A word never spans two lines. */
  words: Array<TextPart>
  /** Every line after wrapping, from the top. */
  lines: Array<TextPart>
  /**
   * False when a glyph could not be matched to a character, as can happen
   * with ligatures and complex scripts. Such a glyph cannot be animated.
   */
  complete: boolean
  private readonly request
  private readonly groups
  private info
  /**
   * @param content - The text. `\n` starts a new line.
   * @param style - Font, size, colour and layout.
   * @param groups - A number for each UTF-16 unit of the content. With it,
   *   a word is a run of characters with the same number instead of a run
   *   between white space; code blocks make their tokens the words this way.
   */
  constructor(
    content: string,
    style?: TextStyle,
    groups?: ReadonlyArray<number>
  )
  /** The layout the text is drawn from, or `null` before it is ready. */
  get textRenderInfo(): TextRenderInfo | null
  /**
   * Does nothing: troika would lay the text out again by itself, at a moment
   * nobody waits for. Layout happens in `framescriptReady` only.
   *
   * @param callback - Called at once.
   */
  sync(callback?: () => void): void
  /**
   * The text's lines, for whatever records which object a tween's target
   * belongs to: the parts are not among `children`.
   *
   * @returns The lines.
   */
  framescriptParts(): ReadonlyArray<TextPart>
  /** The width of the text block, or 0 before the text is ready. */
  get width(): number
  /** The height of the text block, or 0 before the text is ready. */
  get height(): number
  /**
   * What the text costs to draw and to keep: every character that is not
   * white space has a part of its own.
   *
   * @returns The number of such characters.
   */
  framescriptCost(): {
    readonly characters: number
  }
  /**
   * How far below its place a part of this text must stand for none of its
   * glyphs to show inside its line's box, where its line cuts it off. That
   * is the line's height, or more where a glyph reaches further than a line:
   * a tall letter in a tightly set line, or a word that holds an ascender
   * and a descender, whose quad the cut takes in at rest. `rise` and
   * `riseLines` drop a part by what this adds to a line's height.
   *
   * @param part - A line, a word or a character of this text.
   * @returns The distance in the text's own units; 0 for a part of another
   *   text, or before the text is ready.
   */
  framescriptReach(part: object): number
  /**
   * The glyphs the text puts in the atlas of its glyph size, which `add`
   * counts so that a run warns before an atlas outgrows what WebGL holds.
   * A character the font lacks counts as the "?" that stands in for it.
   *
   * @returns Its glyph size, its font and the characters that draw
   *   something, each once.
   */
  framescriptGlyphs(): GlyphUse
  /**
   * What the line that adds the text should be told about it: the
   * characters its font has no glyph for.
   *
   * @returns A note for each thing worth saying; none when all is well.
   */
  framescriptNotes(): ReadonlyArray<ObjectNote>
  /**
   * Lays the text out, which `add` waits for. Layouts are kept, so a text
   * with the same content and style is ready at once the next time.
   *
   * @returns Nothing when the text is ready now; otherwise a promise that
   *   resolves when it is, or when calling again will make it so.
   * @throws When the font could not be read. A character the font has no
   *   glyph for does not throw: a "?" stands in for it, and `framescriptNotes`
   *   says so, which `add` reports as a warning at its line.
   */
  framescriptReady(): Promise<void> | undefined
  private layoutRequest
  private build
  /**
   * What the preparation before a draw writes besides this object's own
   * drawing: nothing, so a player writes no track again for it.
   *
   * @returns No objects.
   */
  framescriptDrawWrites(): ReadonlyArray<object>
  /**
   * Copies the parts' transforms and opacities into the glyphs. Whatever
   * draws the scene calls this after the timeline's values were applied and
   * before it renders; three.js uploads the data too early for a hook of
   * its own to do it.
   */
  framescriptBeforeDraw(): void
  private writeGlyph
  private moved
}

TextPart

TypeScript
class TextPart extends Object3D {
  /** How visible the part is, from 0 to 1. Multiplies with its parents'. */
  opacity: number
  /**
   * Whether the part is cut off at the edges of its own box at rest: 0
   * not at all, anything above 0 wholly. What moves out of the box is then
   * not drawn, so a line can rise into place from behind its lower edge.
   */
  clip: number
  /** The text of the part. */
  content: string
  /** For a character, its position in the source string; otherwise -1. */
  index: number
  /** The parts inside: a line's words or a word's characters. */
  parts: Array<TextPart>
  /** The part's box at rest, in the text's own space. */
  bounds: PartBounds
  /** The centre of the box at rest, in the text's own space. */
  readonly center: Vector3
  /** The glyph a character is drawn with, or -1. */
  glyph: number
  /** Whether this is a line, a word or a character. */
  readonly kind: "line" | "word" | "char"
  /**
   * @param kind - Whether this is a line, a word or a character.
   */
  constructor(kind: "line" | "word" | "char")
  /**
   * The parts inside, for whatever records which object a tween's target
   * belongs to: they are not among `children`.
   *
   * @returns The words of a line or the characters of a word.
   */
  framescriptParts(): ReadonlyArray<TextPart>
  /** The width of the part at rest. */
  get width(): number
  /** The height of the part at rest. */
  get height(): number
}

TextStyle

TypeScript
interface TextStyle {
  /**
   * The URL of a `.ttf`, `.otf` or `.woff` font file. Defaults to the Inter
   * that ships with framescript, which covers Latin only.
   */
  readonly font?: string
  /**
   * The font size, in the units of where the text is: world units in the
   * world, pixels on the screen layer. Defaults to 48, which suits the
   * screen layer; in a scene measured in units, give one.
   */
  readonly fontSize?: number
  /**
   * Picks regular or bold (600 and above) of the default font. With a `font`
   * set, the file decides the weight.
   */
  readonly fontWeight?: number | "normal" | "bold"
  /** The fill colour. Defaults to white. */
  readonly color?: ColorRepresentation
  /**
   * Colours for runs of characters: each key is a position in the content,
   * and its colour applies from that character up to the next key. With it,
   * every glyph has a colour of its own and `color` is not used; give
   * position 0 a colour. The colours are fixed, like the content.
   */
  readonly colorRanges?: Readonly<Record<number, ColorRepresentation>>
  /** The width at which lines wrap. Without it, only `\n` breaks a line. */
  readonly maxWidth?: number
  /** How lines are aligned within the block. Defaults to `"left"`. */
  readonly align?: "left" | "center" | "right" | "justify"
  /** Line height as a multiple of the font size. Defaults to the font's. */
  readonly lineHeight?: number | "normal"
  /** Extra space between characters, in world units. */
  readonly letterSpacing?: number
  /** Which point of the block sits at the object's origin, across. */
  readonly anchorX?: number | "left" | "center" | "right"
  /** Which point of the block sits at the object's origin, down. */
  readonly anchorY?:
    | number
    | "top"
    | "top-baseline"
    | "top-cap"
    | "top-ex"
    | "middle"
    | "bottom-baseline"
    | "bottom"
  /**
   * The resolution of each glyph in the atlas. Defaults to 128; 64 rounds
   * the corners of large titles, 256 is the sharpest. Every text of one
   * size shares one atlas, which holds 1024 glyphs at 256 before it grows
   * past what WebGL can be relied on to hold, so keep the larger sizes for
   * text near the camera.
   */
  readonly sdfGlyphSize?: number
}