Skip to main content

Class: default

Defined in: src/lib/selection/Lasso/index.ts:54

Lasso tool behaviour, independent of the screen: builds rectangle, circle, polygon and freeform mask shapes from pointer input.

  • The keys held when a shape starts choose the mode: Shift adds, Alt subtracts, otherwise it replaces.
  • Rectangle/circle: drag; Shift while dragging keeps sides equal. A click without dragging deselects (in replace mode).
  • Polygon: click to add nodes; Shift snaps the next line to 45°; clicking near the first node, double-clicking or close() finishes it.
  • Freeform: drag; releasing finishes it.
  • cancel() (Escape) abandons the shape in progress.

Example​

lasso.down("rectangle", { x: 10, y: 10 }, keys, false);
lasso.move({ x: 50, y: 30 }, keys);
const result = lasso.up({ x: 50, y: 30 }); // { shape: { type: "rect", ... }, mode: "replace" }

Extends​

  • EventTarget

Constructors​

Constructor​

new default(): Lasso

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14397

Returns​

Lasso

Inherited from​

EventTarget.constructor

Accessors​

active​

Get Signature​

get active(): boolean

Defined in: src/lib/selection/Lasso/index.ts:58

Whether a shape is in progress

Returns​

boolean


nodes​

Get Signature​

get nodes(): readonly Point[]

Defined in: src/lib/selection/Lasso/index.ts:85

Polygon nodes placed so far (for drawing handles)

Returns​

readonly Point[]


preview​

Get Signature​

get preview(): MaskShape | undefined

Defined in: src/lib/selection/Lasso/index.ts:63

The shape in progress, for drawing its outline: rectangles/ellipses, or the polygon/freeform path including the pointer

Returns​

MaskShape | undefined

Methods​

addEventListener()​

addEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14380

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | AddEventListenerOptions

Returns​

void

Inherited from​

EventTarget.addEventListener


cancel()​

cancel(): void

Defined in: src/lib/selection/Lasso/index.ts:177

Abandon the shape in progress (Escape).

Returns​

void


close()​

close(): LassoResult

Defined in: src/lib/selection/Lasso/index.ts:160

Finish a polygon or freeform shape (double-click, Enter, or clicking the first node). Shapes with fewer than three points are abandoned.

Returns​

LassoResult


dispatchEvent()​

dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14386

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters​

event​

Event

Returns​

boolean

Inherited from​

EventTarget.dispatchEvent


down()​

down(kind, point, keys, nearFirstNode): LassoResult

Defined in: src/lib/selection/Lasso/index.ts:94

Pointer pressed.

Parameters​

kind​

LassoKind

point​

Point

keys​

LassoKeys

nearFirstNode​

boolean

whether the pointer is within closing distance of the polygon's first node (on screen)

Returns​

LassoResult


move()​

move(point, keys): void

Defined in: src/lib/selection/Lasso/index.ts:122

Pointer moved (with or without the button held).

Parameters​

point​

Point

keys​

LassoKeys

Returns​

void


removeEventListener()​

removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14392

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | EventListenerOptions

Returns​

void

Inherited from​

EventTarget.removeEventListener


up()​

up(point, keys?): LassoResult

Defined in: src/lib/selection/Lasso/index.ts:142

Pointer released: finishes rectangle, circle and freeform shapes. Polygons continue until closed.

Parameters​

point​

Point

keys?​

LassoKeys = ...

Returns​

LassoResult