Class SplitText<CallbacksMap, StaticProps, MutableProps>

SplitText splits text within a container into individual lines, words, and letters.

Features:

  • Supports resizing, HTML content, and special symbols like emojis.
  • Handles multi-line breaks and non-breaking spaces.
  • Saves initial nodes and listeners for easy restoration.
  • Allows splitting into lines, words, or letters as needed.

Note: Apply fontKerning: none to prevent layout shifts.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

_destroyable: () => void[] = []

Stores actions that need to be executed when the module is destroyed

_isBaseSplit: boolean = false

Tracks whether the text is already split into base elements: words and letters.

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_lettersMeta: ISplitTextLetterMeta[] = []

List of letters metadata.

_linesMeta: ISplitTextLineMeta[] = []

List of lines metadata.

_lineSplitWrapper?: { destroy: () => boolean; linesMeta: ILine[] }

Utility for wrapping words into line containers.

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_savedNodes: { restore: () => void }

Saved initial HTML nodes of the container.

_wordsMeta: ISplitTextWordMeta[] = []

List of words metadata.

Accessors

  • get isDestroyed(): boolean

    Checks if the module has been destroyed.

    Returns boolean

  • get name(): string

    The name of the module, derived from the class name

    Returns string

Methods

  • Adds a class name on an element, and keeps track of it for removal when the module is destroyed.

    Parameters

    • element: Element

      The target DOM element.

    • className: string

      The class name to toggle.

    Returns void

  • Helper function to generate classnames with the module's prefix.

    Parameters

    • ...classNames: string[]

      The class names to generate.

    Returns string

    A string of class names with the module's prefix applied.

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void