import { __require as requireUserAgent } from '../../../../fbjs@2.0.0/node_modules/fbjs/lib/UserAgent.js';
import { __require as requireInvariant } from '../../../../fbjs@2.0.0/node_modules/fbjs/lib/invariant.js';

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 * 
 * @emails oncall+draft_js
 */

var getRangeClientRects_1;
var hasRequiredGetRangeClientRects;

function requireGetRangeClientRects () {
	if (hasRequiredGetRangeClientRects) return getRangeClientRects_1;
	hasRequiredGetRangeClientRects = 1;

	var UserAgent = requireUserAgent();

	var invariant = requireInvariant();

	var isChrome = UserAgent.isBrowser('Chrome'); // In Chrome, the client rects will include the entire bounds of all nodes that
	// begin (have a start tag) within the selection, even if the selection does
	// not overlap the entire node. To resolve this, we split the range at each
	// start tag and join the client rects together.
	// https://code.google.com/p/chromium/issues/detail?id=324437

	/* eslint-disable consistent-return */

	function getRangeClientRectsChrome(range) {
	  var tempRange = range.cloneRange();
	  var clientRects = [];

	  for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
	    // If we've climbed up to the common ancestor, we can now use the
	    // original start point and stop climbing the tree.
	    var atCommonAncestor = ancestor === range.commonAncestorContainer;

	    if (atCommonAncestor) {
	      tempRange.setStart(range.startContainer, range.startOffset);
	    } else {
	      tempRange.setStart(tempRange.endContainer, 0);
	    }

	    var rects = Array.from(tempRange.getClientRects());
	    clientRects.push(rects);

	    if (atCommonAncestor) {
	      var _ref;

	      clientRects.reverse();
	      return (_ref = []).concat.apply(_ref, clientRects);
	    }

	    tempRange.setEndBefore(ancestor);
	  }

	  process.env.NODE_ENV !== "production" ? invariant(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant(false) ;
	}
	/* eslint-enable consistent-return */

	/**
	 * Like range.getClientRects() but normalizes for browser bugs.
	 */


	var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
	  return Array.from(range.getClientRects());
	};
	getRangeClientRects_1 = getRangeClientRects;
	return getRangeClientRects_1;
}

export { requireGetRangeClientRects as __require };
//# sourceMappingURL=getRangeClientRects.js.map
