Class: default
Defined in: src/lib/selection/Selection/index.ts:49
The current mask: a canvas-sized greyscale area (stored as alpha) that limits where drawing applies. Only ever local.
Shapes and layer alpha replace, add to or subtract from it. After each change the mask is measured once to find whether it is empty and to trace its outline (for the animated "crawling ants").
Dispatches a change event whenever the mask changes.
Example
selection.apply({ type: "rect", rect: { x: 10, y: 10, width: 100, height: 50 } }, "replace");
selection.active; // true
selection.outline; // closed loops in canvas pixels
Extends
EventTarget
Constructors
Constructor
new default(
width,height,createCanvas?):Selection
Defined in: src/lib/selection/Selection/index.ts:69
Parameters
width
number
height
number
createCanvas?
CanvasFactory = createOffscreenCanvas
Returns
Selection
Overrides
EventTarget.constructor
Properties
active
active:
boolean=false
Defined in: src/lib/selection/Selection/index.ts:57
Whether a non-empty mask exists
height
readonlyheight:number
Defined in: src/lib/selection/Selection/index.ts:54
Canvas height in pixels
outline
outline:
OutlineLoop[] =[]
Defined in: src/lib/selection/Selection/index.ts:60
Outline of the mask as closed loops in canvas pixels
width
readonlywidth:number
Defined in: src/lib/selection/Selection/index.ts:51
Canvas width in pixels
Accessors
mask
Get Signature
get mask():
OffscreenCanvas|undefined
Defined in: src/lib/selection/Selection/index.ts:81
The mask canvas (alpha = mask value) while a mask is active, for limiting drawing
Returns
OffscreenCanvas | 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.
Parameters
type
string
callback
EventListenerOrEventListenerObject | null
options?
boolean | AddEventListenerOptions
Returns
void
Inherited from
EventTarget.addEventListener
apply()
apply(
shape,mode):void
Defined in: src/lib/selection/Selection/index.ts:96
Replace, add to or subtract from the mask with a lasso shape.
Parameters
shape
mode
Returns
void
clear()
clear():
void
Defined in: src/lib/selection/Selection/index.ts:200
Remove the mask ("cmd + d").
Returns
void
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().
Parameters
event
Event
Returns
boolean
Inherited from
EventTarget.dispatchEvent
fromAlpha()
fromAlpha(
layer,mode?):void
Defined in: src/lib/selection/Selection/index.ts:187
Mask a layer's visible pixels, following their alpha (Cmd/Ctrl + click a layer's name).
Parameters
layer
mode?
MaskMode = "replace"
Returns
void
invert()
invert():
void
Defined in: src/lib/selection/Selection/index.ts:167
Invert the mask: masked parts become unmasked and the rest becomes masked. Without a mask, everything is masked.
Returns
void
moveArea()
moveArea(
piece,from,to,draw):void
Defined in: src/lib/selection/Selection/index.ts:132
Move part of the mask along with transformed pixels: removes the piece from where it was and draws it at its new place.
Parameters
piece
OffscreenCanvas
from
to
draw
(ctx) => void
draws the piece in its new place (e.g. drawTransformed)
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.
Parameters
type
string
callback
EventListenerOrEventListenerObject | null
options?
boolean | EventListenerOptions
Returns
void
Inherited from
EventTarget.removeEventListener
selectAll()
selectAll():
void
Defined in: src/lib/selection/Selection/index.ts:154
Mask the whole canvas ("cmd + a").
Returns
void