{"version":3,"file":"utils.mjs","sources":["../../../../../../packages/components/input/src/utils.ts"],"sourcesContent":["import { isFirefox, isNumber } from '@element-plus/utils'\n\nlet hiddenTextarea: HTMLTextAreaElement | undefined = undefined\n\nconst HIDDEN_STYLE = `\n height:0 !important;\n visibility:hidden !important;\n ${isFirefox() ? '' : 'overflow:hidden !important;'}\n position:absolute !important;\n z-index:-1000 !important;\n top:0 !important;\n right:0 !important;\n`\n\nconst CONTEXT_STYLE = [\n 'letter-spacing',\n 'line-height',\n 'padding-top',\n 'padding-bottom',\n 'font-family',\n 'font-weight',\n 'font-size',\n 'text-rendering',\n 'text-transform',\n 'width',\n 'text-indent',\n 'padding-left',\n 'padding-right',\n 'border-width',\n 'box-sizing',\n]\n\ntype NodeStyle = {\n contextStyle: string\n boxSizing: string\n paddingSize: number\n borderSize: number\n}\n\ntype TextAreaHeight = {\n height: string\n minHeight?: string\n}\n\nfunction calculateNodeStyling(targetElement: Element): NodeStyle {\n const style = window.getComputedStyle(targetElement)\n\n const boxSizing = style.getPropertyValue('box-sizing')\n\n const paddingSize =\n Number.parseFloat(style.getPropertyValue('padding-bottom')) +\n Number.parseFloat(style.getPropertyValue('padding-top'))\n\n const borderSize =\n Number.parseFloat(style.getPropertyValue('border-bottom-width')) +\n Number.parseFloat(style.getPropertyValue('border-top-width'))\n\n const contextStyle = CONTEXT_STYLE.map(\n (name) => `${name}:${style.getPropertyValue(name)}`\n ).join(';')\n\n return { contextStyle, paddingSize, borderSize, boxSizing }\n}\n\nexport function calcTextareaHeight(\n targetElement: HTMLTextAreaElement,\n minRows = 1,\n maxRows?: number\n): TextAreaHeight {\n if (!hiddenTextarea) {\n hiddenTextarea = document.createElement('textarea')\n document.body.appendChild(hiddenTextarea)\n }\n\n const { paddingSize, borderSize, boxSizing, contextStyle } =\n calculateNodeStyling(targetElement)\n\n hiddenTextarea.setAttribute('style', `${contextStyle};${HIDDEN_STYLE}`)\n hiddenTextarea.value = targetElement.value || targetElement.placeholder || ''\n\n let height = hiddenTextarea.scrollHeight\n const result = {} as TextAreaHeight\n\n if (boxSizing === 'border-box') {\n height = height + borderSize\n } else if (boxSizing === 'content-box') {\n height = height - paddingSize\n }\n\n hiddenTextarea.value = ''\n const singleRowHeight = hiddenTextarea.scrollHeight - paddingSize\n\n if (isNumber(minRows)) {\n let minHeight = singleRowHeight * minRows\n if (boxSizing === 'border-box') {\n minHeight = minHeight + paddingSize + borderSize\n }\n height = Math.max(minHeight, height)\n result.minHeight = `${minHeight}px`\n }\n if (isNumber(maxRows)) {\n let maxHeight = singleRowHeight * maxRows\n if (boxSizing === 'border-box') {\n maxHeight = maxHeight + paddingSize + borderSize\n }\n height = Math.min(maxHeight, height)\n }\n result.height = `${height}px`\n hiddenTextarea.parentNode?.removeChild(hiddenTextarea)\n hiddenTextarea = undefined\n\n return result\n}\n"],"names":[],"mappings":";;;;AACA,IAAI,cAAc,GAAG,KAAK,CAAC,CAAC;AAC5B,MAAM,YAAY,GAAG,CAAC;AACtB;AACA;AACA,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,6BAA6B,CAAC;AACrD;AACA;AACA;AACA;AACA,CAAC,CAAC;AACF,MAAM,aAAa,GAAG;AACtB,EAAE,gBAAgB;AAClB,EAAE,aAAa;AACf,EAAE,aAAa;AACf,EAAE,gBAAgB;AAClB,EAAE,aAAa;AACf,EAAE,aAAa;AACf,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAE,gBAAgB;AAClB,EAAE,OAAO;AACT,EAAE,aAAa;AACf,EAAE,cAAc;AAChB,EAAE,eAAe;AACjB,EAAE,cAAc;AAChB,EAAE,YAAY;AACd,CAAC,CAAC;AACF,SAAS,oBAAoB,CAAC,aAAa,EAAE;AAC7C,EAAE,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;AACvD,EAAE,MAAM,SAAS,GAAG,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACzD,EAAE,MAAM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