"use strict";
/**
 *  Ancestor-Aware Styler
 *
 *  Copyright (C) 2010-2020 R-T Specialty, LLC.
 *
 *  This file is part of liza.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNthAncestor = void 0;
/**
 * Helper to get nth ancestor
 *
 * @param element - target element
 * @param n       - number of generations back
 *
 * @return the element's ancestor
 */
exports.getNthAncestor = function (element, n) {
    while (element.parentNode && n-- > 0) {
        element = element.parentNode;
    }
    return n > 0 ? null : element;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQW5jZXN0b3JBd2FyZVN0eWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIkFuY2VzdG9yQXdhcmVTdHlsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBbUJHOzs7QUFTSDs7Ozs7OztHQU9HO0FBQ1UsUUFBQSxjQUFjLEdBQUcsVUFDNUIsT0FBb0IsRUFDcEIsQ0FBa0I7SUFFbEIsT0FBTyxPQUFPLENBQUMsVUFBVSxJQUFJLENBQUMsRUFBRSxHQUFHLENBQUMsRUFBRTtRQUNwQyxPQUFPLEdBQWdCLE9BQU8sQ0FBQyxVQUFVLENBQUM7S0FDM0M7SUFFRCxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDO0FBQ2hDLENBQUMsQ0FBQyJ9