@hummingbirdui/hummingbird
Version:
An open-source system designed for rapid development, without sacrificing the granular control of utility-first CSS.
99 lines (98 loc) • 4.06 kB
JavaScript
;
const baseComponent = require("./base-component.js");
var selectorEngine$1 = { exports: {} };
/*!
* Bootstrap selector-engine.js v5.3.8 (https://getbootstrap.com/)
* Copyright 2011-2025 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
var selectorEngine = selectorEngine$1.exports;
var hasRequiredSelectorEngine;
function requireSelectorEngine() {
if (hasRequiredSelectorEngine) return selectorEngine$1.exports;
hasRequiredSelectorEngine = 1;
(function(module2, exports2) {
(function(global, factory) {
module2.exports = factory(baseComponent.requireUtil());
})(selectorEngine, function(index_js) {
const getSelector = (element) => {
let selector = element.getAttribute("data-bs-target");
if (!selector || selector === "#") {
let hrefAttribute = element.getAttribute("href");
if (!hrefAttribute || !hrefAttribute.includes("#") && !hrefAttribute.startsWith(".")) {
return null;
}
if (hrefAttribute.includes("#") && !hrefAttribute.startsWith("#")) {
hrefAttribute = `#${hrefAttribute.split("#")[1]}`;
}
selector = hrefAttribute && hrefAttribute !== "#" ? hrefAttribute.trim() : null;
}
return selector ? selector.split(",").map((sel) => index_js.parseSelector(sel)).join(",") : null;
};
const SelectorEngine = {
find(selector, element = document.documentElement) {
return [].concat(...Element.prototype.querySelectorAll.call(element, selector));
},
findOne(selector, element = document.documentElement) {
return Element.prototype.querySelector.call(element, selector);
},
children(element, selector) {
return [].concat(...element.children).filter((child) => child.matches(selector));
},
parents(element, selector) {
const parents = [];
let ancestor = element.parentNode.closest(selector);
while (ancestor) {
parents.push(ancestor);
ancestor = ancestor.parentNode.closest(selector);
}
return parents;
},
prev(element, selector) {
let previous = element.previousElementSibling;
while (previous) {
if (previous.matches(selector)) {
return [previous];
}
previous = previous.previousElementSibling;
}
return [];
},
// TODO: this is now unused; remove later along with prev()
next(element, selector) {
let next = element.nextElementSibling;
while (next) {
if (next.matches(selector)) {
return [next];
}
next = next.nextElementSibling;
}
return [];
},
focusableChildren(element) {
const focusables = ["a", "button", "input", "textarea", "select", "details", "[tabindex]", '[contenteditable="true"]'].map((selector) => `${selector}:not([tabindex^="-"])`).join(",");
return this.find(focusables, element).filter((el) => !index_js.isDisabled(el) && index_js.isVisible(el));
},
getSelectorFromElement(element) {
const selector = getSelector(element);
if (selector) {
return SelectorEngine.findOne(selector) ? selector : null;
}
return null;
},
getElementFromSelector(element) {
const selector = getSelector(element);
return selector ? SelectorEngine.findOne(selector) : null;
},
getMultipleElementsFromSelector(element) {
const selector = getSelector(element);
return selector ? SelectorEngine.find(selector) : [];
}
};
return SelectorEngine;
});
})(selectorEngine$1);
return selectorEngine$1.exports;
}
exports.requireSelectorEngine = requireSelectorEngine;
//# sourceMappingURL=selector-engine.js.map