Surface

An abstract class representing the top-level drawing surface. Cannot be directly instantiated.

Specific implementations are created through the static create method. The implementations for SVG and Canvas inherit from this base class.

options SurfaceOptions

Configuration options for the surface.

Methods

bind

Binds to an event on the Surface.

Parameters

eventName SurfaceEventName

The name of the event to bind to.

handler (e: any) => void

The event handler.

Returns

Surface - The current Surface instance to allow chaining.

clear

Clears the drawing surface.

destroy

Releases the resources allocated by this instance.

The DOM elements will not be cleared.

draw

Draws the element and its children on the surface. Existing elements are not affected.

Parameters

element Element

The element to draw.

eventTarget

Returns the target drawing element of a DOM event.

Parameters

e any

The original DOM event object.

Returns

Element - The target drawing element, if any.

one

Binds to an event once. The handler will be unbound after the first event fires.

Parameters

eventName SurfaceEventName

The name of the event to bind to.

handler (e: any) => void

The event handler.

Returns

Surface - The current Surface instance to allow chaining.

resize

Resizes the surface to match the size of the container.

Parameters

force? boolean

Whether to proceed with resizing even if the container dimensions are not changed.

unbind

Unbinds an event handler.

Parameters

eventName SurfaceEventName

The name of the event to bind to.

handler? (e: any) => void

The event handler.

Returns

Surface - The current Surface instance to allow chaining.

create

Creates a drawing surface that matches the browser capabilities.

Parameters

element HTMLElement

The DOM element that will host the surface.

options? SurfaceOptions

The configuration options for the surface.

Returns

Surface - The newly created surface instance.

 /