All files html.ts

100% Statements 14/14
100% Branches 6/6
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27      1x 3x 2x     1x 1x   1x 1x 1x 1x   1x     1x 11x 3x     8x    
/**
 * Gets the client bounding rectangle including any margins of an element.
 */
export function getClientRectWithMargin(element: HTMLElement): ClientRect | DOMRect {
    if (!element) {
        return;
    }
 
    const clone: any = element.getBoundingClientRect();
    const style: CSSStyleDeclaration = window.getComputedStyle(element, null);
 
    clone.width += convertStylePropertyPixelsToNumber(style, "margin-left");
    clone.width += convertStylePropertyPixelsToNumber(style, "margin-right");
    clone.height += convertStylePropertyPixelsToNumber(style, "margin-top");
    clone.height += convertStylePropertyPixelsToNumber(style, "margin-bottom");
 
    return clone;
}
 
export function convertStylePropertyPixelsToNumber(computedStyle: CSSStyleDeclaration, property: string): number {
    if (!computedStyle || !property) {
        return;
    }
 
    return parseInt(computedStyle.getPropertyValue(property).substring(0, computedStyle.getPropertyValue(property).length - 2), 10);
}