Skip to content
On this page

Stage

Stage constructor. A stage is used to contain multiple layers

Stage is essentially a vault where events interact (api events) and contains Layer

in the DOM Stage manifests as a <div> tag

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

Optional Option

NameTypeDefaultDescription
containerMayBeRef<string | HTMLElement>HTMLDivElementSpecified element to represent Layer and event interactions
widthMayBeRef<string>300width length
heightMayBeRef<string>300height length
visibleMayBeRef<boolean>trueIs the stage displayed?
opacityMayBeRef<number>1Sets the opacity of the stage
autoDrawMayBeRef<boolean>trueadded Layer will automatically be drawn
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"option this set 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.$.container = "#app"

console.log(stage.$.container) // "#app"

Computed

size

This computed returns the manifest size of Stage

ts
const { width, height } = stage.size

Methods

mount(query)

This function is a shortcut to set container

ts
mount(query: string | HTMLElement): this;

it is equivalent to:

ts
stage.$.container = query

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
}

add(node)

Add Layer to Stage

ts
add(node: Layer): ChildNodes

destroy()

Destroy Stage

ts
destroy(): void

Released under the MIT License.