@gechiui/dom
Version:
DOM utilities module for GeChiUI.
29 lines (27 loc) • 737 B
JavaScript
/**
* Gets the height of the range without ignoring zero width rectangles, which
* some browsers ignore when creating a union.
*
* @param {Range} range The range to check.
* @return {number | undefined} Height of the range or undefined if the range has no client rectangles.
*/
export default function getRangeHeight(range) {
const rects = Array.from(range.getClientRects());
if (!rects.length) {
return;
}
const highestTop = Math.min(...rects.map(_ref => {
let {
top
} = _ref;
return top;
}));
const lowestBottom = Math.max(...rects.map(_ref2 => {
let {
bottom
} = _ref2;
return bottom;
}));
return lowestBottom - highestTop;
}
//# sourceMappingURL=get-range-height.js.map