(dom: HTMLTextAreaElement)
| 195 | } |
| 196 | |
| 197 | export function autoGrowTextArea(dom: HTMLTextAreaElement) { |
| 198 | const measureDom = getOrCreateMeasureDom("__measure"); |
| 199 | const singleLineDom = getOrCreateMeasureDom("__single_measure", (dom) => { |
| 200 | dom.innerText = "TEXT_FOR_MEASURE"; |
| 201 | }); |
| 202 | |
| 203 | const width = getDomContentWidth(dom); |
| 204 | measureDom.style.width = width + "px"; |
| 205 | measureDom.innerText = dom.value !== "" ? dom.value : "1"; |
| 206 | measureDom.style.fontSize = dom.style.fontSize; |
| 207 | measureDom.style.fontFamily = dom.style.fontFamily; |
| 208 | const endWithEmptyLine = dom.value.endsWith("\n"); |
| 209 | const height = parseFloat(window.getComputedStyle(measureDom).height); |
| 210 | const singleLineHeight = parseFloat( |
| 211 | window.getComputedStyle(singleLineDom).height, |
| 212 | ); |
| 213 | |
| 214 | const rows = |
| 215 | Math.round(height / singleLineHeight) + (endWithEmptyLine ? 1 : 0); |
| 216 | |
| 217 | return rows; |
| 218 | } |
| 219 | |
| 220 | export function getCSSVar(varName: string) { |
| 221 | return getComputedStyle(document.body).getPropertyValue(varName).trim(); |
no test coverage detected