import { TextStyle , Dimension } from './types' ; import getBBoxCeil from './svg/getBBoxCeil' ; import { hiddenSvgFactory , textFactory } from './svg/factories' ; import updateTextNode from './svg/updateTextNode' ; param input param defaultDimension export default function getMultipleTextDimensions ( input , defaultDimension ? ) { const { texts , className , style , container } = input ; const cache = new Map < string , Dimension > ( ) ; cache . set ( '' , { height : 0 , width : 0 } ) ; let textNode ; let svgNode ; const dimensions = texts . map ( text => { if ( cache . has ( text ) ) { return cache . get ( text ) as Dimension ; } if ( ! textNode ) { svgNode = hiddenSvgFactory . createInContainer ( container ) ; textNode = textFactory . createInContainer ( svgNode ) ; } updateTextNode ( textNode , { className , style , text } ) ; const dimension = getBBoxCeil ( textNode , defaultDimension ) ; cache . set ( text , dimension ) ; return dimension ; } ) ; if ( svgNode && textNode ) { setTimeout ( ( ) => { textFactory . removeFromContainer ( svgNode ) ; hiddenSvgFactory . removeFromContainer ( container ) ; } , 500 ) ; } return dimensions ; }