@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
53 lines • 2.34 kB
JavaScript
import { getNodeName } from './node';
import { getUAString } from './userAgent';
export const isHTMLElement = (value) => {
return value instanceof window.HTMLElement;
};
export const isElement = (value) => {
return value instanceof window.Element;
};
export const isShadowRoot = (node) => {
// Some browsers do not suppeort "ShadowRoot"
if (typeof ShadowRoot === 'undefined') {
return false;
}
return node instanceof window.ShadowRoot || node instanceof ShadowRoot;
};
export const isTableElement = (element) => {
return ['table', 'td', 'th'].includes(getNodeName(element));
};
export const isWebKit = () => {
if (typeof CSS === 'undefined' || !CSS.supports)
return false;
return CSS.supports('-webkit-backdrop-filter', 'none');
};
export const isContainingBlock = (element) => {
const webkit = 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)));
};
export const isLastTraversableNode = (node) => {
return ['html', 'body', '#document'].includes(getNodeName(node));
};
export 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));
};
/**
* 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.
*/
export function isClientRectVisualViewportBased() {
return /^((?!chrome|android).)*safari/i.test(getUAString());
}
//# sourceMappingURL=is.utils.js.map