51 lines
902 B
JavaScript
51 lines
902 B
JavaScript
|
export class Box {
|
||
|
constructor(_ref) {
|
||
|
let {
|
||
|
x,
|
||
|
y,
|
||
|
width,
|
||
|
height
|
||
|
} = _ref;
|
||
|
this.x = x;
|
||
|
this.y = y;
|
||
|
this.width = width;
|
||
|
this.height = height;
|
||
|
}
|
||
|
get top() {
|
||
|
return this.y;
|
||
|
}
|
||
|
get bottom() {
|
||
|
return this.y + this.height;
|
||
|
}
|
||
|
get left() {
|
||
|
return this.x;
|
||
|
}
|
||
|
get right() {
|
||
|
return this.x + this.width;
|
||
|
}
|
||
|
}
|
||
|
export function getOverflow(a, b) {
|
||
|
return {
|
||
|
x: {
|
||
|
before: Math.max(0, b.left - a.left),
|
||
|
after: Math.max(0, a.right - b.right)
|
||
|
},
|
||
|
y: {
|
||
|
before: Math.max(0, b.top - a.top),
|
||
|
after: Math.max(0, a.bottom - b.bottom)
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
export function getTargetBox(target) {
|
||
|
if (Array.isArray(target)) {
|
||
|
return new Box({
|
||
|
x: target[0],
|
||
|
y: target[1],
|
||
|
width: 0,
|
||
|
height: 0
|
||
|
});
|
||
|
} else {
|
||
|
return target.getBoundingClientRect();
|
||
|
}
|
||
|
}
|
||
|
//# sourceMappingURL=box.mjs.map
|