Files
v10/dist/dev/dom/utils/layout.js

57 lines
1.6 KiB
JavaScript

import { isString } from "@videojs/utils/predicate";
//#region src/dom/utils/layout.ts
function forceLayout(element) {
element?.getBoundingClientRect();
}
function createDOMRect(left, top, width, height) {
const right = left + width;
const bottom = top + height;
return {
x: left,
y: top,
width,
height,
top,
right,
bottom,
left,
toJSON() {
return {
x: left,
y: top,
width,
height,
top,
right,
bottom,
left
};
}
};
}
function intersectDOMRects(firstRect, secondRect) {
const left = Math.max(firstRect.left, secondRect.left);
const top = Math.max(firstRect.top, secondRect.top);
const right = Math.min(firstRect.right, secondRect.right);
const bottom = Math.min(firstRect.bottom, secondRect.bottom);
return createDOMRect(left, top, Math.max(0, right - left), Math.max(0, bottom - top));
}
function getPositioningBoundaryRect(boundaryElement) {
const viewportRect = document.documentElement.getBoundingClientRect();
return boundaryElement ? intersectDOMRects(viewportRect, boundaryElement.getBoundingClientRect()) : viewportRect;
}
function resolvePositioningBoundary(boundary, options = {}) {
if (!boundary) return null;
if (!isString(boundary)) return boundary;
if (boundary === "viewport") return null;
if (boundary === "container") return options.container ?? null;
try {
return (options.root ?? document).querySelector(boundary);
} catch {
return null;
}
}
//#endregion
export { createDOMRect, forceLayout, getPositioningBoundaryRect, intersectDOMRects, resolvePositioningBoundary };
//# sourceMappingURL=layout.js.map