UNPKG

tdesign-mobile-vue

Version:
75 lines (69 loc) 3.11 kB
/** * tdesign v1.15.1 * (c) 2026 TDesign Group * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _common_js_utils_helper = require('./helper.js'); var isNull = require('../../../_chunks/dep-a08136a2.js'); require('@babel/runtime/helpers/toConsumableArray'); require('@babel/runtime/helpers/objectWithoutProperties'); require('@babel/runtime/helpers/slicedToArray'); require('@babel/runtime/helpers/defineProperty'); require('../../../_chunks/dep-e30b9275.js'); require('../../../_chunks/dep-8fb16430.js'); require('../../../_chunks/dep-71520daa.js'); require('@babel/runtime/helpers/typeof'); require('../../../_chunks/dep-e226a2cc.js'); require('../../../_chunks/dep-bc41faad.js'); require('../../../_chunks/dep-24107aa3.js'); var TEXTAREA_STYLE = "\n min-height:0 !important;\n max-height:none !important;\n height:0 !important;\n visibility:hidden !important;\n overflow:hidden !important;\n position:absolute !important;\n z-index:-1000 !important;\n top:0 !important;\n right:0 !important\n"; function calcTextareaHeight(targetElement) { var minRows = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var maxRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var hiddenTextarea = document.createElement("textarea"); document.body.appendChild(hiddenTextarea); try { var _calculateNodeSize = _common_js_utils_helper.calculateNodeSize(targetElement), paddingSize = _calculateNodeSize.paddingSize, borderSize = _calculateNodeSize.borderSize, boxSizing = _calculateNodeSize.boxSizing, sizingStyle = _calculateNodeSize.sizingStyle; hiddenTextarea.setAttribute("style", "".concat(sizingStyle, ";").concat(TEXTAREA_STYLE)); hiddenTextarea.value = targetElement.value || targetElement.placeholder || ""; var height = hiddenTextarea.scrollHeight; var result = {}; var isBorderbox = boxSizing === "border-box"; var isContentbox = boxSizing === "content-box"; if (isBorderbox) { height += borderSize; } else if (isContentbox) { height -= paddingSize; } hiddenTextarea.value = ""; var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; var calcHeight = function calcHeight(rows) { var rowsHeight = singleRowHeight * rows; if (isBorderbox) { rowsHeight = rowsHeight + paddingSize + borderSize; } return rowsHeight; }; if (!isNull.isNull(minRows)) { var minHeight = calcHeight(minRows); height = Math.max(minHeight, height); result.minHeight = "".concat(minHeight, "px"); } if (!isNull.isNull(maxRows)) { height = Math.min(calcHeight(maxRows), height); } result.height = "".concat(height, "px"); return result; } finally { var _hiddenTextarea$paren; (_hiddenTextarea$paren = hiddenTextarea.parentNode) === null || _hiddenTextarea$paren === void 0 || _hiddenTextarea$paren.removeChild(hiddenTextarea); } } exports["default"] = calcTextareaHeight; //# sourceMappingURL=calcTextareaHeight.js.map