'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var instanceOf = require('./instanceOf.js');
var math = require('../utils/math.js');
var getWindow = require('./getWindow.js');
var isLayoutViewport = require('./isLayoutViewport.js');

function getBoundingClientRect(element, includeScale, isFixedStrategy) {
  if (includeScale === void 0) {
    includeScale = false;
  }

  if (isFixedStrategy === void 0) {
    isFixedStrategy = false;
  }

  var clientRect = element.getBoundingClientRect();
  var scaleX = 1;
  var scaleY = 1;

  if (includeScale && instanceOf.isHTMLElement(element)) {
    scaleX = element.offsetWidth > 0 ? math.round(clientRect.width) / element.offsetWidth || 1 : 1;
    scaleY = element.offsetHeight > 0 ? math.round(clientRect.height) / element.offsetHeight || 1 : 1;
  }

  var _ref = instanceOf.isElement(element) ? getWindow.default(element) : window,
      visualViewport = _ref.visualViewport;

  var addVisualOffsets = !isLayoutViewport.default() && isFixedStrategy;
  var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
  var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
  var width = clientRect.width / scaleX;
  var height = clientRect.height / scaleY;
  return {
    width: width,
    height: height,
    top: y,
    right: x + width,
    bottom: y + height,
    left: x,
    x: x,
    y: y
  };
}

exports.default = getBoundingClientRect;
//# sourceMappingURL=getBoundingClientRect.js.map
