import { Arr } from '@ephox/katamari';
import { Height, SugarLocation, Width, WindowVisualViewport } from '@ephox/sugar';
import * as OuterPosition from '../frame/OuterPosition';
const pointed = (point, width, height) => ({
    point,
    width,
    height
});
const rect = (x, y, width, height) => ({
    x,
    y,
    width,
    height
});
const bounds = (x, y, width, height) => ({
    x,
    y,
    width,
    height,
    right: x + width,
    bottom: y + height
});
const box = (element) => {
    const xy = SugarLocation.absolute(element);
    const w = Width.getOuter(element);
    const h = Height.getOuter(element);
    return bounds(xy.left, xy.top, w, h);
};
// NOTE: We used to use AriaFocus.preserve here, but there is no reason to do that now that
// we are not changing the visibility of the element. Hopefully (2015-09-29).
const absolute = (element) => {
    const position = OuterPosition.find(element);
    const width = Width.getOuter(element);
    const height = Height.getOuter(element);
    return bounds(position.left, position.top, width, height);
};
const constrain = (original, constraint) => {
    const left = Math.max(original.x, constraint.x);
    const top = Math.max(original.y, constraint.y);
    const right = Math.min(original.right, constraint.right);
    const bottom = Math.min(original.bottom, constraint.bottom);
    const width = right - left;
    const height = bottom - top;
    return bounds(left, top, width, height);
};
const constrainByMany = (original, constraints) => {
    return Arr.foldl(constraints, (acc, c) => constrain(acc, c), original);
};
const win = () => WindowVisualViewport.getBounds(window);
export { pointed, rect, bounds, box, absolute, win, constrain, constrainByMany };
//# sourceMappingURL=Boxes.js.map