image-sketchpad - v1.0.4 / Modules / Canvas / Canvas
Canvas.Canvas
Canvas helper class. Inserts {@link HTMLCanvasElement|element} and handles position and size adjustments.
• new Canvas()
Creates an instance of the canvas helper class.
• Readonly
element: HTMLCanvasElement
Reference to the HTML canvas {@link HTMLCanvasElement|element}.
▸ adjust(width
, height
, top
, left
): void
Adjusts canvas size and position.
Name | Type | Description |
---|---|---|
width |
number |
New width for canvas. |
height |
number |
New height for canvas. |
top |
number |
New top position for canvas. |
left |
number |
New left position for canvas. |
void
▸ adjustFromElement(element
): void
Adjust canvas size and position from existing element.
Name | Type | Description |
---|---|---|
element |
HTMLElement |
Existing {@link HTMLElement|element} as reference. |
void
▸ clear(): Canvas
Clear the canvas area.
▸ drawStroke(stroke
, ratio
): Promise
<void
>
Draw stroke as a path on canvas area.
Name | Type | Description |
---|---|---|
stroke |
Stroke |
Stroke object with meta data. |
ratio |
number |
Image/canvas ratio. |
Promise
<void
>
▸ insert(refElement
): void
Inserts canvas html element right after the reference element.
Name | Type | Description |
---|---|---|
refElement |
HTMLElement |
Reference {@link HTMLElement|element} where we want position the canvas. |
void