# canvas-drawable

> Make canvas element drawable

Latest version **1.0.10** (published 2019-08-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install canvas-drawable
pnpm add canvas-drawable
yarn add canvas-drawable
bun add canvas-drawable
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2019-08-21 |
| First published | 2018-01-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lam |
| Maintainers | lamm |
| Keywords | canvas, drawable, html, html5, edit |

## Links

- npm: https://www.npmjs.com/package/canvas-drawable
- Repository: https://github.com/doublelam/canvas-drawable
- Homepage: https://github.com/doublelam/canvas-drawable#readme
- Issues: https://github.com/doublelam/canvas-drawable/issues
- npm.io page: https://npm.io/package/canvas-drawable

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^9.4.1

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.10 (latest) — 2019-08-21
- 1.0.9 — 2018-03-14
- 1.0.8 — 2018-03-14
- 1.0.7 — 2018-02-07
- 1.0.6 — 2018-02-04
- 1.0.5 — 2018-02-04
- 1.0.4 — 2018-01-24
- 1.0.3 — 2018-01-23
- 1.0.2 — 2018-01-21
- 1.0.1 — 2018-01-03
- 1.0.0 — 2018-01-02

## README

# Get start
A package that let the specified canvas elememnt turns to drawable, it can be used to draw things or erase  
```
  npm install canvas-drawable --save
```

## Usage

``` pug
html(lang="en")
  head
    meta(charset="UTF-8")
    meta(name="viewport", content="width=device-width, initial-scale=1.0")
    meta(http-equiv="X-UA-Compatible", content="ie=edge")
    title canvas
  body
    canvas#canvas(style="margin: 30px;border: 50px solid #eee" width="300px" height="200px")
    button#erase erase
    button#draw draw
    button#getimage getimg
    button#clearall clear all
```

``` ts
import { CanvasDrawable } from "canvas-drawable";
const canvas: HTMLCanvasElement = <HTMLCanvasElement>document.getElementById('canvas');
const erase = document.getElementById('erase');
const draw = document.getElementById('draw');
const getImage = document.getElementById('getimage');
const clearAll = document.getElementById('clearall');
const drawable = new CanvasDrawable(canvas.getContext('2d'));
erase.onclick = e => {
  drawable.enerase();
}
draw.onclick = e => {
  drawable.endraw();
}
getImage.onclick = e => {
  console.log(drawable.getCanvasBase64())
}
clearAll.onclick = e => {
  drawable.cleanAll();
}
```

## Methods

### new CanvasDrawable(canvasContext, style?: {color: string, width: number})

### endraw()
let the canvas element be drawable

### enerase(thick?:number)
change the mode into erase besides change the thick of erase

### setStyle(style: {color?: string, width?: number})
set the style of stroke

### cleanAll()
clean the whole area of the canvas element

### getCanvasBase64(...args);
returns canvasContext.canvas.toDataURL(...args);

### getCanvasBlob(...args);
returns a promise that will return the blob of the canvas image

### nativeContext()
return the convasContext

---
_Source: https://npm.io/package/canvas-drawable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
