{"version":3,"file":"getTextAreaHeight.utils.cjs","sources":["../../../../../../src/components/forms/text-area/hooks/utils/getTextAreaHeight.utils.ts"],"sourcesContent":["import type { TextAreaHeightOptions } from '@components/forms/text-area/hooks/types'\r\nimport { getLineHeight } from '@components/forms/text-area/hooks/utils/getLineHeight.utils'\r\nimport { getVerticalExtras } from '@components/forms/text-area/hooks/utils/getVerticalExtras.utils'\r\n\r\n/**\r\n * Computes the height (in px) a `<textarea>` should have to fit its content\r\n * between `minRows` and `maxRows`, based on its current computed style and\r\n * `scrollHeight`.\r\n */\r\nexport const getTextAreaHeight = (el: HTMLTextAreaElement, { minRows, maxRows }: TextAreaHeightOptions): number => {\r\n    const computed = window.getComputedStyle(el)\r\n    const lineHeight = getLineHeight(computed)\r\n    const verticalExtras = getVerticalExtras(computed)\r\n\r\n    const minHeight = minRows !== undefined ? minRows * lineHeight + verticalExtras : undefined\r\n    const maxHeight = maxRows !== undefined ? maxRows * lineHeight + verticalExtras : undefined\r\n\r\n    // Reset height to auto so scrollHeight reflects the content size.\r\n    el.style.height = 'auto'\r\n    let newHeight = el.scrollHeight\r\n\r\n    if (minHeight !== undefined) {\r\n        newHeight = Math.max(newHeight, minHeight)\r\n    }\r\n    if (maxHeight !== undefined) {\r\n        newHeight = Math.min(newHeight, maxHeight)\r\n    }\r\n\r\n    return newHeight\r\n}\r\n"],"names":["getTextAreaHeight","el","minRows","maxRows","computed","lineHeight","getLineHeight","verticalExtras","getVerticalExtras","minHeight","maxHeight","newHeight"],"mappings":"wKASaA,EAAoB,CAACC,EAAyB,CAAE,QAAAC,EAAS,QAAAC,KAA6C,CAC/G,MAAMC,EAAW,OAAO,iBAAiBH,CAAE,EACrCI,EAAaC,EAAAA,cAAcF,CAAQ,EACnCG,EAAiBC,EAAAA,kBAAkBJ,CAAQ,EAE3CK,EAAYP,IAAY,OAAYA,EAAUG,EAAaE,EAAiB,OAC5EG,EAAYP,IAAY,OAAYA,EAAUE,EAAaE,EAAiB,OAGlFN,EAAG,MAAM,OAAS,OAClB,IAAIU,EAAYV,EAAG,aAEnB,OAAIQ,IAAc,SACdE,EAAY,KAAK,IAAIA,EAAWF,CAAS,GAEzCC,IAAc,SACdC,EAAY,KAAK,IAAIA,EAAWD,CAAS,GAGtCC,CACX"}