@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
65 lines • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isOverflowElement = exports.isLastTraversableNode = exports.isContainingBlock = exports.isWebKit = exports.isTableElement = exports.isShadowRoot = exports.isElement = exports.isHTMLElement = void 0;
exports.isClientRectVisualViewportBased = isClientRectVisualViewportBased;
const node_1 = require("./node");
const userAgent_1 = require("./userAgent");
const isHTMLElement = (value) => {
return value instanceof window.HTMLElement;
};
exports.isHTMLElement = isHTMLElement;
const isElement = (value) => {
return value instanceof window.Element;
};
exports.isElement = isElement;
const isShadowRoot = (node) => {
// Some browsers do not suppeort "ShadowRoot"
if (typeof ShadowRoot === 'undefined') {
return false;
}
return node instanceof window.ShadowRoot || node instanceof ShadowRoot;
};
exports.isShadowRoot = isShadowRoot;
const isTableElement = (element) => {
return ['table', 'td', 'th'].includes((0, node_1.getNodeName)(element));
};
exports.isTableElement = isTableElement;
const isWebKit = () => {
if (typeof CSS === 'undefined' || !CSS.supports)
return false;
return CSS.supports('-webkit-backdrop-filter', 'none');
};
exports.isWebKit = isWebKit;
const isContainingBlock = (element) => {
const webkit = (0, exports.isWebKit)();
const css = getComputedStyle(element);
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
return (css.transform !== 'none' ||
css.perspective !== 'none' ||
(css.containerType ? css.containerType !== 'normal' : false) ||
(!webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false)) ||
(!webkit && (css.filter ? css.filter !== 'none' : false)) ||
['transform', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) ||
['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value)));
};
exports.isContainingBlock = isContainingBlock;
const isLastTraversableNode = (node) => {
return ['html', 'body', '#document'].includes((0, node_1.getNodeName)(node));
};
exports.isLastTraversableNode = isLastTraversableNode;
const isOverflowElement = (element) => {
const { overflow, overflowX, overflowY, display } = window.getComputedStyle(element);
return (/auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) &&
!['inline', 'contents'].includes(display));
};
exports.isOverflowElement = isOverflowElement;
/**
* Determines whether or not `.getBoundingClientRect()` is affected by visual
* viewport offsets. In Safari, the `x`/`y` offsets are values relative to the
* visual viewport, while in other engines, they are values relative to the
* layout viewport.
*/
function isClientRectVisualViewportBased() {
return /^((?!chrome|android).)*safari/i.test((0, userAgent_1.getUAString)());
}
//# sourceMappingURL=is.utils.js.map