You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
9.0 KiB
1 line
9.0 KiB
3 months ago
|
{"ast":null,"code":"import '../../../utils/index.mjs';\nimport { isFirefox } from '../../../utils/browser.mjs';\nimport { isNumber } from '../../../utils/types.mjs';\nlet hiddenTextarea = void 0;\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`;\nconst CONTEXT_STYLE = [\"letter-spacing\", \"line-height\", \"padding-top\", \"padding-bottom\", \"font-family\", \"font-weight\", \"font-size\", \"text-rendering\", \"text-transform\", \"width\", \"text-indent\", \"padding-left\", \"padding-right\", \"border-width\", \"box-sizing\"];\nfunction calculateNodeStyling(targetElement) {\n const style = window.getComputedStyle(targetElement);\n const boxSizing = style.getPropertyValue(\"box-sizing\");\n const paddingSize = Number.parseFloat(style.getPropertyValue(\"padding-bottom\")) + Number.parseFloat(style.getPropertyValue(\"padding-top\"));\n const borderSize = Number.parseFloat(style.getPropertyValue(\"border-bottom-width\")) + Number.parseFloat(style.getPropertyValue(\"border-top-width\"));\n const contextStyle = CONTEXT_STYLE.map(name => `${name}:${style.getPropertyValue(name)}`).join(\";\");\n return {\n contextStyle,\n paddingSize,\n borderSize,\n boxSizing\n };\n}\nfunction calcTextareaHeight(targetElement, minRows = 1, maxRows) {\n var _a;\n if (!hiddenTextarea) {\n hiddenTextarea = document.createElement(\"textarea\");\n document.body.appendChild(hiddenTextarea);\n }\n const {\n paddingSize,\n borderSize,\n boxSizing,\n contextStyle\n } = calculateNodeStyling(targetElement);\n hiddenTextarea.setAttribute(\"style\", `${contextStyle};${HIDDEN_STYLE}`);\n hiddenTextarea.value = targetElement.value || targetElement.placeholder || \"\";\n let height = hiddenTextarea.scrollHeight;\n const result = {};\n if (boxSizing === \"border-box\") {\n height = height + borderSize;\n } else if (boxSizing === \"content-box\") {\n height = height - paddingSize;\n }\n hiddenTextarea.value = \"\";\n const singleRowHeight = hiddenTextarea.scrollHeight - paddingSize;\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 (_a = hiddenTextarea.parentNode) == null ? void 0 : _a.removeChild(hiddenTextarea);\n hiddenTextarea = void 0;\n return result;\n}\nexport { calcTextareaHeight };","map":{"version":3,"names":["hiddenTextarea","HIDDEN_STYLE","isFirefox","CONTEXT_STYLE","calculateNodeStyling","targetElement","style","window","getComputedStyle","boxSizing","getPropertyValue","paddingSize","Number","parseFloat","borderSize","contextStyle","map","name","join","calcTextareaHeight","minRows","maxRows","_a","document","createElement","body","appendChild","setAttribute","value","placeholder","height","scrollHeight","result","singleRowHeight","isNumber","minHeight","Math","max","maxHeight","min","parentNode","removeChild"],"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'
|