UNPKG

@skbkontur/ui-kit

Version:

73 lines 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function getPositionObject(position) { var x = position.split(' '); return { direction: x[0], align: x[1] }; } function getElementAbsoluteRect(element) { var rect = _getElementRelativeRect(element); return convertRectToAbsolute(rect); } function isAbsoluteRectFullyVisible(absoluteRect) { var windowRelativeRect = _getWindowRelativeRect(); var windowAbsoluteRect = convertRectToAbsolute(windowRelativeRect); return _rectContainsRect(windowAbsoluteRect, absoluteRect); } function _getElementRelativeRect(element) { var rect = element.getBoundingClientRect(); return { top: rect.top, left: rect.left, width: rect.right - rect.left, height: rect.bottom - rect.top }; } function _getWindowRelativeRect() { return { top: 0, left: 0, width: _getViewProperty(function (x) { return x.clientWidth; }) || window.innerWidth, height: _getViewProperty(function (x) { return x.clientHeight; }) || window.innerHeight }; } function convertRectToAbsolute(rect) { var offset = _getAbsoluteOffset(); return { top: rect.top + offset.top, left: rect.left + offset.left, width: rect.width, height: rect.height }; } function _getAbsoluteOffset() { var scrollTop = window.pageYOffset || _getViewProperty(function (x) { return x.scrollTop; }); var scrollLeft = window.pageXOffset || _getViewProperty(function (x) { return x.scrollLeft; }); var clientTop = _getViewProperty(function (x) { return x.clientTop; }); var clientLeft = _getViewProperty(function (x) { return x.clientLeft; }); var top = scrollTop - clientTop; var left = scrollLeft - clientLeft; return { top: top, left: left }; } function _rectContainsRect(outerRect, innerRect) { return (innerRect.top > outerRect.top && innerRect.top + innerRect.height < outerRect.top + outerRect.height && innerRect.left > outerRect.left && innerRect.left + innerRect.width < outerRect.left + outerRect.width); } function _getViewProperty(getProperty) { var views = [document.documentElement, document.body]; var viewProperties = views.map(function (item) { return item && getProperty(item); }); return viewProperties.find(function (item) { return !!item; }) || 0; } exports.default = { getPositionObject: getPositionObject, getElementAbsoluteRect: getElementAbsoluteRect, isAbsoluteRectFullyVisible: isAbsoluteRectFullyVisible }; //# sourceMappingURL=PopupHelper.js.map