Rect (utils/dom)
@ckeditor/ckeditor5-utils/src/dom/rect
A helper class representing a ClientRect
object, e.g. value returned by
the native object.getBoundingClientRect()
method. Provides a set of methods
to manipulate the rect and compare it against other rect instances.
Filtering
Properties
-
bottom : number
module:utils/dom/rect~Rect#bottom
The "bottom" value of the rect.
-
height : number
module:utils/dom/rect~Rect#height
The "height" value of the rect.
-
left : number
module:utils/dom/rect~Rect#left
The "left" value of the rect.
-
right : number
module:utils/dom/rect~Rect#right
The "right" value of the rect.
-
top : number
module:utils/dom/rect~Rect#top
The "top" value of the rect.
-
width : number
module:utils/dom/rect~Rect#width
The "width" value of the rect.
-
The object this rect is for.
Methods
-
constructor( source )
module:utils/dom/rect~Rect#constructor
Creates an instance of rect.
// Rect of an HTMLElement. const rectA = new Rect( document.body ); // Rect of a DOM Range. const rectB = new Rect( document.getSelection().getRangeAt( 0 ) ); // Rect of a window (web browser viewport). const rectC = new Rect( window ); // Rect out of an object. const rectD = new Rect( { top: 0, right: 10, bottom: 10, left: 0, width: 10, height: 10 } ); // Rect out of another Rect instance. const rectE = new Rect( rectD ); // Rect out of a ClientRect. const rectF = new Rect( document.body.getClientRects().item( 0 ) );
Note: By default a rect of an HTML element includes its CSS borders and scrollbars (if any) ant the rect of a
window
includes scrollbars too. UseexcludeScrollbarsAndBorders
to get the inner part of the rect.Parameters
source : RectSource
A source object to create the rect.
-
-
contains( anotherRect ) → boolean
module:utils/dom/rect~Rect#contains
Checks whether a rect fully contains another rect instance.
Parameters
anotherRect : Rect
Returns
boolean
true
if contains,false
otherwise.
-
excludeScrollbarsAndBorders() → Rect
module:utils/dom/rect~Rect#excludeScrollbarsAndBorders
-
getArea() → number
module:utils/dom/rect~Rect#getArea
-
getIntersection( anotherRect ) → null | Rect
module:utils/dom/rect~Rect#getIntersection
-
getIntersectionArea( anotherRect ) → number
module:utils/dom/rect~Rect#getIntersectionArea
Returns the area of intersection with another rect.
Parameters
anotherRect : Rect
Returns
number
Area of intersection.
-
getVisible() → null | Rect
module:utils/dom/rect~Rect#getVisible
Returns a new rect, a part of the original rect, which is actually visible to the user and is relative to the,
body
, e.g. an original rect cropped by parent element rects which haveoverflow
set in CSS other than"visible"
.If there's no such visible rect, which is when the rect is limited by one or many of the ancestors,
null
is returned.Note: This method does not consider the boundaries of the viewport (window). To get a rect cropped by all ancestors and the viewport, use an intersection such as:
const visibleInViewportRect = new Rect( window ).getIntersection( new Rect( source ).getVisible() );
Returns
null | Rect
A visible rect instance or
null
, if there's none.
-
isEqual( anotherRect ) → boolean
module:utils/dom/rect~Rect#isEqual
-
Moves the rect in–place by a dedicated offset.
Parameters
x : number
A horizontal offset.
y : number
A vertical offset
Returns
Rect
A rect which has been moved.
-
Moves the rect so that its upper–left corner lands in desired
[ x, y ]
location.Parameters
x : number
Desired horizontal location.
y : number
Desired vertical location.
Returns
Rect
A rect which has been moved.
-
toAbsoluteRect() → Rect
module:utils/dom/rect~Rect#toAbsoluteRect
Recalculates screen coordinates to coordinates relative to the positioned ancestor offset.
Returns
Static methods
-
Returns an array of rects of the given native DOM Range.
Parameters
range : Range
A native DOM range.
Returns
Array<Rect>
DOM Range rects.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.