All files / src/projection/utils measure.ts

45.45% Statements 5/11
0% Branches 0/2
50% Functions 1/2
45.45% Lines 5/11

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 28 29 30 31 32 3334x       34x       34x       80x         34x                              
import {
    convertBoundingBoxToBox,
    transformBoxPoints,
} from "../geometry/conversion"
import { translateAxis } from "../geometry/delta-apply"
import { TransformPoint } from "../geometry/types"
import { IProjectionNode } from "../node/types"
 
export function measureViewportBox(
    instance: HTMLElement,
    transformPoint?: TransformPoint
) {
    return convertBoundingBoxToBox(
        transformBoxPoints(instance.getBoundingClientRect(), transformPoint)
    )
}
 
export function measurePageBox(
    element: HTMLElement,
    rootProjectionNode: IProjectionNode,
    transformPagePoint?: TransformPoint
) {
    const viewportBox = measureViewportBox(element, transformPagePoint)
    const { scroll } = rootProjectionNode
 
    if (scroll) {
        translateAxis(viewportBox.x, scroll.x)
        translateAxis(viewportBox.y, scroll.y)
    }
 
    return viewportBox
}