"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = isOverflow;

var _measureTextWidth = _interopRequireDefault(require("../_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;
}

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((0, _measureTextWidth["default"])(textContent || value, computedStyle));
      return textWidth > contentWidth;
    }
  }

  return false;
}
//# sourceMappingURL=util.js.map
