function filterParsed(selector, elements, options) {
    if (elements.length === 0)
        return [];
    var _a = (0, helpers_js_1.groupSelectors)(selector), plainSelectors = _a[0], filteredSelectors = _a[1];
    var found;
    if (plainSelectors.length) {
        var filtered = filterElements(elements, plainSelectors, options);
        // If there are no filters, just return
        if (filteredSelectors.length === 0) {
            return filtered;
        }
        // Otherwise, we have to do some filtering
        if (filtered.length) {
            found = new Set(filtered);
        }
    }
    for (var i = 0; i < filteredSelectors.length && (found === null || found === void 0 ? void 0 : found.size) !== elements.length; i++) {
        var filteredSelector = filteredSelectors[i];
        var missing = found
            ? elements.filter(function (e) { return DomUtils.isTag(e) && !found.has(e); })
            : elements;
        if (missing.length === 0)
            break;
        var filtered = filterBySelector(filteredSelector, elements, options);
        if (filtered.length) {
            if (!found) {
                /*
                 * If we haven't found anything before the last selector,
                 * just return what we found now.
                 */
                if (i === filteredSelectors.length - 1) {
                    return filtered;
                }
                found = new Set(filtered);
            }
            else {
                filtered.forEach(function (el) { return found.add(el); });
            }
        }
    }
    return typeof found !== "undefined"
        ? (found.size === elements.length
            ? elements
            : // Filter elements to preserve order
                elements.filter(function (el) {
                    return found.has(el);
                }))
        : [];
}
/**
 * Filter a set of elements by a selector.
 *
 * Will return elements in the original order.
 *
 * @param selector Selector to filter by.
 * @param elements Elements to filter.
 * @param options Options for selector.
 */
Filter a set of elements by a selector.
Will return elements in the original order.

@param selector Selector to filter by.
@param elements Elements to filter.
@param options Options for selector.
Filter a set of elements by a selector . Will return elements in the original order . @param selector Selector to filter by . @param elements Elements to filter . @param options Options for selector .
function filterParsed(selector, elements, options) {
    if (elements.length === 0)
        return [];
    var _a = (0, helpers_js_1.groupSelectors)(selector), plainSelectors = _a[0], filteredSelectors = _a[1];
    var found;
    if (plainSelectors.length) {
        var filtered = filterElements(elements, plainSelectors, options);
        if (filteredSelectors.length === 0) {
            return filtered;
        }
        if (filtered.length) {
            found = new Set(filtered);
        }
    }
    for (var i = 0; i < filteredSelectors.length && (found === null || found === void 0 ? void 0 : found.size) !== elements.length; i++) {
        var filteredSelector = filteredSelectors[i];
        var missing = found
            ? elements.filter(function (e) { return DomUtils.isTag(e) && !found.has(e); })
            : elements;
        if (missing.length === 0)
            break;
        var filtered = filterBySelector(filteredSelector, elements, options);
        if (filtered.length) {
            if (!found) {
                if (i === filteredSelectors.length - 1) {
                    return filtered;
                }
                found = new Set(filtered);
            }
            else {
                filtered.forEach(function (el) { return found.add(el); });
            }
        }
    }
    return typeof found !== "undefined"
        ? (found.size === elements.length
            ? elements
            : 
                elements.filter(function (el) {
                    return found.has(el);
                }))
        : [];
}
function filterParsed ( selector , elements , options ) { if ( elements . length === 0 ) return [ ] ; var _a = ( 0 , helpers_js_1 . groupSelectors ) ( selector ) , plainSelectors = _a [ 0 ] , filteredSelectors = _a [ 1 ] ; var found ; if ( plainSelectors . length ) { var filtered = filterElements ( elements , plainSelectors , options ) ; if ( filteredSelectors . length === 0 ) { return filtered ; } if ( filtered . length ) { found = new Set ( filtered ) ; } } for ( var i = 0 ; i < filteredSelectors . length && ( found === null || found === void 0 ? void 0 : found . size ) !== elements . length ; i ++ ) { var filteredSelector = filteredSelectors [ i ] ; var missing = found ? elements . filter ( function ( e ) { return DomUtils . isTag ( e ) && ! found . has ( e ) ; } ) : elements ; if ( missing . length === 0 ) break ; var filtered = filterBySelector ( filteredSelector , elements , options ) ; if ( filtered . length ) { if ( ! found ) { if ( i === filteredSelectors . length - 1 ) { return filtered ; } found = new Set ( filtered ) ; } else { filtered . forEach ( function ( el ) { return found . add ( el ) ; } ) ; } } } return typeof found !== "undefined" ? ( found . size === elements . length ? elements : elements . filter ( function ( el ) { return found . has ( el ) ; } ) ) : [ ] ; }
Filter a set of elements by a selector.
Filter a set of elements by a selector .
// If there are no filters, just return // Otherwise, we have to do some filtering /*
                 * If we haven't found anything before the last selector,
                 * just return what we found now.
                 */ // Filter elements to preserve order