"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DomInnermost = void 0;
const index_js_1 = require("../model/index.js");
class DomInnermost 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 innermost = true;
            for (let j = 0; j < inputSet.length; j += 1) {
                const otherEl = inputSet[j];
                if (i === j) {
                    continue;
                }
                if (await el.remote.contains(otherEl.remote)) {
                    innermost = false;
                    break;
                }
            }
            if (innermost) {
                results.push(el);
            }
        }
        return results;
    }
}
exports.DomInnermost = DomInnermost;
DomInnermost.$type = 'DOM.innermost';
DomInnermost.$help = `
Discards elements that enclose other elements from the same set.
This leaves only the "innermost" 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.outermost: for the inverse functionality
`;
//# sourceMappingURL=DOM.innermost.js.map