box.mjs 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. export class Box {
  2. constructor(_ref) {
  3. let {
  4. x,
  5. y,
  6. width,
  7. height
  8. } = _ref;
  9. this.x = x;
  10. this.y = y;
  11. this.width = width;
  12. this.height = height;
  13. }
  14. get top() {
  15. return this.y;
  16. }
  17. get bottom() {
  18. return this.y + this.height;
  19. }
  20. get left() {
  21. return this.x;
  22. }
  23. get right() {
  24. return this.x + this.width;
  25. }
  26. }
  27. export function getOverflow(a, b) {
  28. return {
  29. x: {
  30. before: Math.max(0, b.left - a.left),
  31. after: Math.max(0, a.right - b.right)
  32. },
  33. y: {
  34. before: Math.max(0, b.top - a.top),
  35. after: Math.max(0, a.bottom - b.bottom)
  36. }
  37. };
  38. }
  39. export function getTargetBox(target) {
  40. if (Array.isArray(target)) {
  41. return new Box({
  42. x: target[0],
  43. y: target[1],
  44. width: 0,
  45. height: 0
  46. });
  47. } else {
  48. return target.getBoundingClientRect();
  49. }
  50. }
  51. //# sourceMappingURL=box.mjs.map