"use strict";
/**
 *  LeftAlignAncestorAwareStyler
 *
 *  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.LeftAlignAncestorAwareStyler = void 0;
var AncestorAwareStyler_1 = require("./AncestorAwareStyler");
/**
 * Styles an HTML element's left position based on an ancestor
 */
var LeftAlignAncestorAwareStyler = /** @class */ (function () {
    function LeftAlignAncestorAwareStyler() {
    }
    /**
     * Align the element with an ancestor by adjusting its left positon
     *
     * @param element - target element
     * @param n       - number of generations back
     */
    LeftAlignAncestorAwareStyler.prototype.style = function (element, generation) {
        var ancestor = AncestorAwareStyler_1.getNthAncestor(element, generation);
        if (!ancestor) {
            return;
        }
        /**
         * Reset style.left when it is out of sync with DOMRect.left
         *
         * If this styler is applied while the element is hidden, it will use
         * a DOMRect.left of 0 which applies an inaccurate style.left to the
         * element. As a result, the next time the styler is applied, it will
         * continue as if the origin of the target element has been relocated to
         * the previously set style.left.
         */
        element.style.left = '0px';
        var ancestor_rect = ancestor.getBoundingClientRect();
        var element__rect = element.getBoundingClientRect();
        element.style.left = ancestor_rect.left - element__rect.left + 'px';
    };
    return LeftAlignAncestorAwareStyler;
}());
exports.LeftAlignAncestorAwareStyler = LeftAlignAncestorAwareStyler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTGVmdEFsaWduQW5jZXN0b3JBd2FyZVN0eWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIkxlZnRBbGlnbkFuY2VzdG9yQXdhcmVTdHlsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBbUJHOzs7QUFFSCw2REFBMEU7QUFHMUU7O0dBRUc7QUFDSDtJQUFBO0lBNkJBLENBQUM7SUE1QkM7Ozs7O09BS0c7SUFDSSw0Q0FBSyxHQUFaLFVBQWEsT0FBb0IsRUFBRSxVQUEyQjtRQUM1RCxJQUFNLFFBQVEsR0FBRyxvQ0FBYyxDQUFDLE9BQU8sRUFBRSxVQUFVLENBQUMsQ0FBQztRQUVyRCxJQUFJLENBQUMsUUFBUSxFQUFFO1lBQ2IsT0FBTztTQUNSO1FBRUQ7Ozs7Ozs7O1dBUUc7UUFDSCxPQUFPLENBQUMsS0FBSyxDQUFDLElBQUksR0FBRyxLQUFLLENBQUM7UUFFM0IsSUFBTSxhQUFhLEdBQUcsUUFBUSxDQUFDLHFCQUFxQixFQUFFLENBQUM7UUFDdkQsSUFBTSxhQUFhLEdBQUcsT0FBTyxDQUFDLHFCQUFxQixFQUFFLENBQUM7UUFDdEQsT0FBTyxDQUFDLEtBQUssQ0FBQyxJQUFJLEdBQUcsYUFBYSxDQUFDLElBQUksR0FBRyxhQUFhLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQztJQUN0RSxDQUFDO0lBQ0gsbUNBQUM7QUFBRCxDQUFDLEFBN0JELElBNkJDO0FBN0JZLG9FQUE0QiJ9