UNPKG

@kelvininc/ui-components

Version:
27 lines (26 loc) 1.17 kB
import { isNil } from "lodash-es"; import { DEFAULT_CONFIG } from "../globals/config"; export const getConfig = () => { if (typeof window !== 'undefined') { const KvUiComponents = window.KvUiComponents; if (!isNil(KvUiComponents) && !isNil(KvUiComponents.config)) { return KvUiComponents.config; } } return DEFAULT_CONFIG; }; export const getCollapsedElement = (elements) => { var _a; if (elements.length === 0) { return; } const [firstElement, ...siblings] = elements; if (isOverflowEllipsis(firstElement)) { return firstElement; } return (_a = getCollapsedElement(Array.from(firstElement.childNodes))) !== null && _a !== void 0 ? _a : getCollapsedElement(siblings); }; export const isOverflowEllipsis = (element) => !isNodeText(element) && !isNodeComment(element) && getCssStyle(element, 'text-overflow') === 'ellipsis'; export const isNodeText = (element) => element.nodeName === '#text'; export const isNodeComment = (element) => element.nodeName === '#comment'; export const getCssStyle = (element, prop) => window.getComputedStyle(element, null).getPropertyValue(prop);