Composables

useSplitText

Documentation for useSplitText composable.

Reactive wrapper for the splitText function from AnimeJS.

A lightweight, responsive and accessible text utility function to split, clone and wrap lines, words and characters of an HTML Element.

Type Definition

function useSplitText(
  target: SplitTextTargets,
  parameters: TextSplitterParams
): {
  lines: Ref<HTMLElement[]>,
  words: Ref<HTMLElement[]>,
  chars: Ref<HTMLElement[]>,
  properties: ComputedRef<NonFunctionProperties<TextSplitter>>,
  revert: () => void,
  split: () => void,
  refresh: () => void,
}

Arguments

target
SplitTextTargets required
The element or selector containing the text to split.
parameters
TextSplitterParams
See AnimeJS Text documentation for split options like lines, words, chars.

Sample usage

import { stagger } from '#nanime/utils'
const text = useTemplateRef('phrase')

const { chars } = useSplitText(text, {
  chars: true,
})

useAnimate(chars, {
  y: [{ to: '-30%' }, { to: 0 }],
  delay: stagger(50),
  duration: 600,
  ease: 'inOutCirc',
  loop: true,
})
Hello World!

Return Value

Returns an object with reactive references to the split elements and helper methods.

PropertyTypeDescription
linesRef<HTMLElement[]>Array containing line elements.
wordsRef<HTMLElement[]>Array containing word elements.
charsRef<HTMLElement[]>Array containing character elements.
propertiesComputedRef<object>The underlying TextSplitter properties.
split() => voidManually trigger split.
revert() => voidRevert the DOM to its original state.
refresh() => voidRe-calculate splits (useful on resize).

API

Types

type SplitTargets = HTMLElement | string
type SplitTextTargets = SplitTargets | MaybeElementRef<HTMLElement> | null | undefined | MaybeElementRef<VueInstance>

See AnimeJS Text documentation for more details.

Copyright © 2026