UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

28 lines 924 B
import "core-js/modules/es.string.replace.js"; import { warn } from '../helpers'; export const getPreviousSibling = (selector, element) => { try { const tagName = /[A-Z]/.test(selector) ? selector : null; const className = tagName ? null : selector.replace(/^\./, ''); const contains = element => { if (!element) { return null; } if (tagName) { return (element === null || element === void 0 ? void 0 : element.tagName) === tagName; } return element === null || element === void 0 ? void 0 : element.classList.contains(className); }; if (contains(element)) { return element; } while ((element = (_element = element) === null || _element === void 0 ? void 0 : _element.parentElement) && !contains(element)) { var _element; ; } } catch (e) { warn(e); } return element; }; //# sourceMappingURL=getPreviousSibling.js.map