Need private packages and team management tools?Check out npm Teams »


3.22.0 • Public • Published

spase npm CircleCI

Micro library for performing spatial calculations of DOM elements.


import * as spase from 'spase';


Class: Point

A class for defining structure and utilities for 2D vectors.

Class: Rect

A class for defining a rectangle on a 2D plane.


Computes the intersecting rect of one or more elements. If only 1 element is specified, the intersection will be computed against the viewport.

  • @param elements: Element[] — Element(s) to be used to compute the intersecting rect.
  • @return Rect | null — The intersecting rect.

Rect.from(target[, options])

Gets the combined rect of one or more elements.

  • @param target: Rect | Window | Element | Element[] — An element or array of elements to compute the combined rect.
  • @param options — Additional options.
  • @param options.reference: Window | Element | undefined — The element whose coordinate space the computed top, right, bottom and left values are relative to.
  • @param options.overflow: boolean - Specifies whether the overflow width/height should be accounted for.
  • @return Rect | null — The combined rect.


Gets the rect of the viewport (current field of view). Think of this as the rect of the current window.

  • @return Rect — The rect of the viewport.

Class: Size

A class for defining structure and utilities for sizes.

hitTest(obj1, obj2)

Hit-tests 2 objects. These objects can either be a single point, Rect instance(s) or Element instance(s).

  • @param obj1: Rect | Element | Element[] | Point | readonly [number number] | Readonly<{ x: number; y: number; }> | Rect[] — First object.
  • @param obj2: Rect | Element | Element[] | Point | Rect[] — Second object.
  • @return booleantrue if test passes, false otherwise.

Breaking Changes


  • API changes: getIntersectRect, getRect, and getViewportRect are now static members of Rect class, as Rect.intersecting, Rect.from, and Rect.fromViewport, respectively.


npm i spase

DownloadsWeekly Downloads






Unpacked Size

82 kB

Total Files


Last publish


  • avatar