"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DomOutermost = void 0;
const index_js_1 = require("../model/index.js");
class DomOutermost extends index_js_1.Pipe {
    async apply(inputSet, _ctx) {
        const results = [];
        for (let i = 0; i < inputSet.length; i += 1) {
            const el = inputSet[i];
            let outermost = true;
            for (let j = 0; j < inputSet.length; j += 1) {
                const otherEl = inputSet[j];
                if (i === j) {
                    continue;
                }
                if (await otherEl.remote.contains(el.remote)) {
                    outermost = false;
                    break;
                }
            }
            if (outermost) {
                results.push(el);
            }
        }
        return results;
    }
}
exports.DomOutermost = DomOutermost;
DomOutermost.$type = 'DOM.outermost';
DomOutermost.$help = `
Discards elements that are enclosed by other elements from the same set.
This leaves only the "outermost" elements in the output set.

### Use For

- squashing element sets that are loosely defined,
  in particular if website does not have semantic DOM structure to work with

### See Also

- DOM.innermost: for the inverse functionality
`;
//# sourceMappingURL=DOM.outermost.js.map