namespace Connected.Interop { public class BoundingClientRect { public double Top { get; set; } public double Left { get; set; } public double Width { get; set; } public double Height { get; set; } /// /// height of the viewport /// public double WindowHeight { get; set; } /// /// width of the viewport /// public double WindowWidth { get; set; } /// /// the horizontal offset since the left of the page /// public double ScrollX { get; set; } /// /// the vertical offset since the top of the page /// public double ScrollY { get; set; } // computed properties, read only public double X => Left; public double Y => Top; public double Bottom => Top + Height; public double Right => Left + Width; public double AbsoluteLeft => Left + ScrollX; public double AbsoluteTop => Top + ScrollY; public double AbsoluteRight => Right + ScrollX; public double AbsoluteBottom => Bottom + ScrollY; //check if the rect is outside of the viewport public bool IsOutsideBottom => Bottom > WindowHeight; public bool IsOutsideLeft => Left < 0; public bool IsOutsideTop => Top < 0; public bool IsOutsideRight => Right > WindowWidth; public BoundingClientRect Clone() { return new BoundingClientRect { Left = Left, Top = Top, Width = Width, Height = Height, WindowHeight = WindowHeight, WindowWidth = WindowWidth, ScrollX = ScrollX, ScrollY = ScrollY }; } } public static class BoundingClientRectExtensions { public static bool IsEqualTo(this BoundingClientRect sourceRect, BoundingClientRect targetRect) { if (sourceRect is null || targetRect is null) return false; return sourceRect.Top == targetRect.Top && sourceRect.Left == targetRect.Left && sourceRect.Width == targetRect.Width && sourceRect.Height == targetRect.Height && sourceRect.WindowHeight == targetRect.WindowHeight && sourceRect.WindowWidth == targetRect.WindowWidth && sourceRect.ScrollX == targetRect.ScrollX && sourceRect.ScrollY == targetRect.ScrollY; } } }