| | |
| | | export const arrayIsEmpty = (arr: any) => { |
| | | return !arr || arr.length === 0; |
| | | }; |
| | | |
| | | type GetTextWidthOption = { |
| | | size?: string; |
| | | family?: string; |
| | | }; |
| | | |
| | | export function getTextWidth(text: string, option: GetTextWidthOption) { |
| | | const { size = '14px', family = 'Microsoft YaHei' } = option; |
| | | const spanEle = document.createElement('span'); |
| | | document.body.appendChild(spanEle); |
| | | |
| | | spanEle.style.font = 'times new roman'; |
| | | spanEle.style.fontSize = size; |
| | | spanEle.style.height = 'auto'; |
| | | spanEle.style.width = 'auto'; |
| | | spanEle.style.position = 'absolute'; |
| | | spanEle.style.whiteSpace = 'no-wrap'; |
| | | spanEle.innerHTML = text; |
| | | |
| | | const width = spanEle.clientWidth; |
| | | |
| | | document.body.removeChild(spanEle); |
| | | return width; |
| | | } |