UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

49 lines (39 loc) 1.64 kB
import measureTextWidth from '../_util/measureTextWidth'; function getContentWidth(element, computedStyle) { var width = computedStyle.width, boxSizing = computedStyle.boxSizing; if (boxSizing === 'content-box' && width && width !== 'auto') { return parseFloat(width); } var contentWidth = width && width !== 'auto' ? parseFloat(width) : element.offsetWidth; var paddingLeft = computedStyle.paddingLeft, paddingRight = computedStyle.paddingRight, borderLeftWidth = computedStyle.borderLeftWidth, borderRightWidth = computedStyle.borderRightWidth; var pl = paddingLeft ? parseFloat(paddingLeft) : 0; var pr = paddingRight ? parseFloat(paddingRight) : 0; var bl = borderLeftWidth ? parseFloat(borderLeftWidth) : 0; var br = borderRightWidth ? parseFloat(borderRightWidth) : 0; return contentWidth - pl - pr - bl - br; } export default function isOverflow(element) { var textContent = element.textContent, ownerDocument = element.ownerDocument; var value = element.value; if ((value || textContent) && ownerDocument) { var clientWidth = element.clientWidth, scrollWidth = element.scrollWidth; if (scrollWidth > clientWidth) { return true; } var defaultView = ownerDocument.defaultView; if (defaultView) { var computedStyle = defaultView.getComputedStyle(element); var contentWidth = Math.round(getContentWidth(element, computedStyle)); var textWidth = Math.round(measureTextWidth(textContent || value, computedStyle)); return textWidth > contentWidth; } } return false; } //# sourceMappingURL=util.js.map