Skip to content
On this page

Layer

Layer contains Shape and Group which represent an actual drawn canvas

In addition, this shape also provides a few other parameters:

Optional Option

NameTypeDefaultDescription
widthMayBeRef<string>= Stage width ?? 300width length
heightMayBeRef<string>= Stage height ?? 300height length
visibleMayBeRef<boolean>trueIs the stage displayed?
opacityMayBeRef<number>1Sets the opacity of the stage
clipMayBeRef<Rect | Path2D>undefinedThe layer will be clipped whether it accepts a Rect or Path2D
autoDrawMayBeRef<boolean>trueadded Layer will automatically be drawn
clearBeforeDrawMayBeRef<boolean>trueclear after draw?
offscreenMayBeRef<boolean>falseif it is true the stage will not show anything. the container option will be disabled. you don't need to care about this it is automatically installed in different environments like browser, nodejs, worker...
filterMayBeRef<"none" | Filter>"none"filter
xMayBeRef<number>0x from option Transform
yMayBeRef<number>0y from option Transform
scaleMayBeRef<{ x: number; y: number }>{ x: 1, y: 1 }scale from option Transform
rotationMayBeRef<number>0rotation from option Transform
offsetMayBeRef<{ x: number; y: number }>{ x: 1, y: 1 }offset from option Transform
skewXMayBeRef<number>1skewX from option Transform
skewYMayBeRef<number>1skewY from option Transform
ts
interface Filter {
  url?: string // string
  blur?: number // px
  brightness?: number // int%
  contrast?: number // 0 -> 100%
  dropShadow?: {
    x?: number
    y?: number
    blur?: number // intpx > 0
    color: string
  }
  greyscale?: number // int%
  hueRotate?: number // 0 -> 360 deg
  invert?: number // int%
  opacity?: number // 0 -> 100%
  saturate?: number // int%
  sepia?: number // int%
}

Get

$ (as attrs)

A Proxy that contains all the settings allowing to get/set the value of props and react automatically

ts
stage.$.clearBeforeDraw = false

console.log(stage.$.clearBeforeDraw) // false

uid

A uid Layer. Return value is string

Methods

getBoundingClientRect()

This function returns the size and position of the expression of Stage it's the same as Element.getBoundingClientRect

ts
getBoundingClientRect(): {
  width: number
  height: number
  x: number
  y: number
}

draw()

Make Layer draw once. It returns a boolean that checks if the Layer needs redraw

ts
draw(): boolean

batchDraw()

Smart redraw. This function will redraw Layer continuously until stopDraw() is called.

If it detects that Layer doesn't need to be redrawn it will pause the drawing process and wait until the Layer changes and resume drawing.

TIP

This function is automatically called if autoDraw !== false

ts
batchDraw(): void

stopDraw()

Stop the continuous redraw called with batchDraw()

ts
stopDraw(): void

add(node)

Add an element to Layer. node is Shape or Group

ts
add(node: Shape | Group): ChildNodes

delete(node)

Delete an element to Layer. node is Shape or Group

ts
delete(node: Shape | Group): boolean

isPressedPoint(x, y)

Check if the point with coordinates {x,y} is in Layer or not

ts
isPressedPoint(x: number, y: number): boolean

addTo(stage)

Where to add Layer

ts
addTo(stage: Stage): void

it is equivalent to

ts
stage.add(layer)

destroy()

Destroy Layer

ts
destroy(): void

Released under the MIT License.