Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
while (target !== null) {
// Set up the match array for this DOM level.
let matches: IItem[] = [];
// Search the remaining items for matches.
for (let i = 0, n = availableItems.length; i < n; ++i) {
// Fetch the item.
let item = availableItems[i];
// Skip items which are already consumed.
if (!item) {
continue;
}
// Skip items which do not match the element.
if (!Selector.matches(target, item.selector)) {
continue;
}
// Add the matched item to the result for this DOM level.
matches.push(item);
// Mark the item as consumed.
availableItems[i] = null;
}
// Sort the matches for this level and add them to the results.
if (matches.length !== 0) {
matches.sort(itemCmp);
result.push(...matches);
}
function targetDistance(selector: string, event: KeyboardEvent): number {
let targ = event.target as (Element | null);
let curr = event.currentTarget as (Element | null);
for (let dist = 0; targ !== null; targ = targ.parentElement, ++dist) {
if (targ.hasAttribute('data-p-suppress-shortcuts')) {
return -1;
}
if (Selector.matches(targ, selector)) {
return dist;
}
if (targ === curr) {
return -1;
}
}
return -1;
}