"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.alignAtCenter = exports.alignAtTargetZoneRightEdge = exports.alignAtTargetZoneLeftEdge = exports.projectTargetZoneLeftEdge = exports.targetZoneRightEdge = exports.targetZoneLeftEdge = exports.getTileTargetZoneOffsets = exports.getTargetZoneOffsets = exports.centerOffset = exports.rightEdgeOffset = exports.leftEdgeOffset = exports.scrollPosition = void 0;
var tiles_1 = require("./tiles");
/*
  scrollLeft is a decimal on some browsers/devices
  rounding it to an integer avoids some nefarious edge cases
*/
exports.scrollPosition = function (el) { return Math.round(el.scrollLeft); };
/*
  an elements position relative to its parent's containing box
*/
exports.leftEdgeOffset = function (el) { return el.offsetLeft; };
exports.rightEdgeOffset = function (el) {
    return (el.offsetLeft + el.offsetWidth);
};
exports.centerOffset = function (el) {
    return (el.offsetLeft + el.offsetWidth / 2);
};
exports.getTargetZoneOffsets = function (container, meaningfulChildren) {
    if (meaningfulChildren.length < 1) {
        return {
            left: 0,
            right: container.scrollWidth
        };
    }
    var first = meaningfulChildren[0];
    var last = meaningfulChildren[meaningfulChildren.length - 1];
    return {
        left: exports.leftEdgeOffset(first),
        right: container.scrollWidth - exports.rightEdgeOffset(last)
    };
};
exports.getTileTargetZoneOffsets = function (container) {
    var tiles = tiles_1.getTiles(container);
    return exports.getTargetZoneOffsets(container, tiles);
};
exports.targetZoneLeftEdge = function (container, targetOffset) {
    return exports.scrollPosition(container) + targetOffset.left;
};
exports.targetZoneRightEdge = function (container, targetOffset) {
    return exports.scrollPosition(container) + container.clientWidth - targetOffset.right;
};
exports.projectTargetZoneLeftEdge = function (scrollPosition, targetOffset) {
    return scrollPosition + targetOffset.left;
};
/*
  the position the container should be scrolled to to align it
  as requested with the given element
*/
exports.alignAtTargetZoneLeftEdge = function (container, targetOffset, el) {
    return exports.leftEdgeOffset(el) - targetOffset.left;
};
exports.alignAtTargetZoneRightEdge = function (container, targetOffset, el) {
    return exports.rightEdgeOffset(el) + targetOffset.right - container.clientWidth;
};
exports.alignAtCenter = function (container, el) {
    return exports.centerOffset(el) - container.clientWidth / 2;
};
