UNPKG

dtd

Version:

根据数梦工场视觉规范打造的组件库,感谢react-components和ant design

1 lines 2.54 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=calculateNodeHeight;var HIDDEN_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",SIZING_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"],computedStyleCache={},hiddenTextarea=void 0;function calculateNodeStyling(e){var t=1<arguments.length&&void 0!==arguments[1]&&arguments[1],i=e.getAttribute("id")||e.getAttribute("data-reactid")||e.getAttribute("name");if(t&&computedStyleCache[i])return computedStyleCache[i];var r=window.getComputedStyle(e),a=r.getPropertyValue("box-sizing")||r.getPropertyValue("-moz-box-sizing")||r.getPropertyValue("-webkit-box-sizing"),n=parseFloat(r.getPropertyValue("padding-bottom"))+parseFloat(r.getPropertyValue("padding-top")),o=parseFloat(r.getPropertyValue("border-bottom-width"))+parseFloat(r.getPropertyValue("border-top-width")),d={sizingStyle:SIZING_STYLE.map(function(e){return e+":"+r.getPropertyValue(e)}).join(";"),paddingSize:n,borderSize:o,boxSizing:a};return t&&i&&(computedStyleCache[i]=d),d}function calculateNodeHeight(e){var t=1<arguments.length&&void 0!==arguments[1]&&arguments[1],i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null;hiddenTextarea||(hiddenTextarea=document.createElement("textarea"),document.body.appendChild(hiddenTextarea)),e.getAttribute("wrap")?hiddenTextarea.setAttribute("wrap",e.getAttribute("wrap")):hiddenTextarea.removeAttribute("wrap");var a=calculateNodeStyling(e,t),n=a.paddingSize,o=a.borderSize,d=a.boxSizing,l=a.sizingStyle;hiddenTextarea.setAttribute("style",l+";"+HIDDEN_TEXTAREA_STYLE),hiddenTextarea.value=e.value||e.placeholder||"";var p=Number.MIN_SAFE_INTEGER,g=Number.MAX_SAFE_INTEGER,u=hiddenTextarea.scrollHeight,h=void 0;if("border-box"===d?u+=o:"content-box"===d&&(u-=n),null!==i||null!==r){hiddenTextarea.value=" ";var b=hiddenTextarea.scrollHeight-n;null!==i&&(p=b*i,"border-box"===d&&(p=p+n+o),u=Math.max(p,u)),null!==r&&(g=b*r,"border-box"===d&&(g=g+n+o),h=g<u?"":"hidden",u=Math.min(g,u))}return r||(h="hidden"),{height:u,minHeight:p,maxHeight:g,overflowY:h}}module.exports=exports.default;