All files / src/projection/node HTMLProjectionNode.ts

91.67% Statements 11/12
83.33% Branches 5/6
66.67% Functions 2/3
91.67% Lines 11/12

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 2734x 34x     34x       34x           519x 33x 33x 33x 33x   519x     1x      
import { createProjectionNode } from "./create-projection-node"
import { DocumentProjectionNode } from "./DocumentProjectionNode"
import { IProjectionNode } from "./types"
 
export const rootProjectionNode: { current: IProjectionNode | undefined } = {
    current: undefined,
}
 
export const HTMLProjectionNode = createProjectionNode<HTMLElement>({
    measureScroll: (instance) => ({
        x: instance.scrollLeft,
        y: instance.scrollTop,
    }),
    defaultParent: () => {
        if (!rootProjectionNode.current) {
            const documentNode = new DocumentProjectionNode(0, {})
            documentNode.mount(window)
            documentNode.setOptions({ layoutScroll: true })
            rootProjectionNode.current = documentNode
        }
        return rootProjectionNode.current
    },
    resetTransform: (instance, value) => {
        instance.style.transform = value ?? "none"
    },
})