function element ( innerHTML ? ) { const el = document . createElement ( 'div' ) ; el . setAttribute ( 'style' , 'display:inline-block;position:relative;text-align:start' ) ; el . innerHTML = innerHTML || '' ; return el ; } /**
 * Detects words and characters from a target or a list of targets.
 * Note: if multiple targets are detected, they will return as a single
 * list of characters and numbers
 */ export function splitText ( target ) { const characters = [ ] ; const words = [ ] ; const elements = typeof target === 'string' ? ( document . querySelectorAll ( target as string ) as any ) : target instanceof Element ? [ target as HTMLElement ] : typeof ( target as any [ ] ) . length === 'number' ? target : [ ] ; for ( let i = 0 , ilen = elements . length ; i < ilen ; i ++ ) { var e = elements [ i ] ; if ( ! e ) { continue ; } var contents = e . textContent ! . replace ( /[\r\n\s\t]+/gi , ' ' ) . trim ( ) ; e . innerHTML = '' ; var ws = contents . split ( /[\s]+/gi ) ; for ( let x = 0 , xlen = ws . length ; x < xlen ; x ++ ) { var w = ws [ x ] ; if ( ! w ) { continue ; } if ( x > 0 ) { var empty = element ( '&nbsp;' ) ; e . appendChild ( empty ) ; } var word = element ( ) ; words . push ( word ) ; e . appendChild ( word ) ; for ( let y = 0 , ylen = w . length ; y < ylen ; y ++ ) { var c = w [ y ] ; var character = element ( c ) ; word . appendChild ( character ) ; characters . push ( character ) ; } } } return { characters , words } ; }