@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
56 lines (55 loc) • 2 kB
JavaScript
class m {
/**
* Calculate the available space in all directions between a trigger element & the edges of the screen or a defined
* container element.
*
* @param triggerElement The trigger element to calculate available space.
* @param maxWidth Maximum available width (screen width or placement container width).
* @param maxHeight Maximum available height (screen height or placement container height).
* @param placementContainer Bounding container to use for calculation.
*
* @returns An object defining the available space from the trigger element to the screen or
* container edge in each direction.
*/
static calculateAvailableSpace(o, e, i, n) {
const t = o.getBoundingClientRect(), a = {
top: t.top,
bottom: i - t.bottom,
left: t.left,
right: e - t.right
};
if (n) {
const h = n.getBoundingClientRect(), c = {
top: Math.max(t.top - h.top, 0),
bottom: Math.max(h.bottom - t.bottom, 0),
left: Math.max(t.left - h.left, 0),
right: Math.max(h.right - t.right, 0)
};
return {
top: Math.min(a.top, c.top),
bottom: Math.min(a.bottom, c.bottom),
left: Math.min(a.left, c.left),
right: Math.min(a.right, c.right)
};
}
return a;
}
/**
* Calculate the maximum available on screen width & height of an element.
*
* @param placementContainer The element for which to calculate the maximum width & height.
*
* @returns The maximum width & height of the element.
*/
static calculateBounds(o) {
const e = document.documentElement, i = document.body.getBoundingClientRect(), n = i.height + i.y, t = i.width + i.x;
return {
maxWidth: o ? Math.min(o.offsetWidth, e.clientWidth, t) : Math.min(e.clientWidth, t),
maxHeight: o ? Math.min(o.offsetHeight, e.clientHeight, n) : Math.min(e.clientHeight, n)
};
}
}
export {
m as NeonPlacementUtils
};
//# sourceMappingURL=NeonPlacementUtils.es.js.map