# elem-canvas

> Canvas rendering library, Sprite manipulation of canvas

Latest version **1.1.2** (published 2022-04-17) · MIT License license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2022-04-17 |
| First published | 2022-04-07 |
| Weekly downloads | 0 |
| License | MIT License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 110.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Alex |
| Maintainers | gypeng.alex |
| Keywords | el-canvas, canvas, render, element |

## Links

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

## Dependencies (1)

- [@tweenjs/tween.js](https://npm.io/package/@tweenjs/tween.js.md) ^18.6.4

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2022-04-17
- 1.1.1 — 2022-04-13
- 1.1.0 — 2022-04-12
- 1.0.9 — 2022-04-12
- 1.0.8 — 2022-04-12
- 1.0.6 — 2022-04-11
- 1.0.5 — 2022-04-08
- 1.0.4 — 2022-04-08
- 1.0.1 — 2022-04-07
- 1.0.0 — 2022-04-07

## README

# el-canvas

[<img width="100px" align="middle" src="https://raw.githubusercontent.com/GYPeng/elem-canvas/a8127bfc15e5445fbe8678ff72608dfb8b96a3dc/logo.svg"/>]()

Canvas rendering library, Sprite manipulation of canvas

## hello world

```html
<div id="app"></div>
```

```
  yarn add elem-canvas

    or

  npm i elem-canvas
```

```js
import { Root, Sprite } from "elem-canvas";

const app = new Root(document.getElementById("app"));

const root = new Sprite({
  x: (window.innerWidth - 300) / 2,
  y: (window.innerHeight - 300) / 2,
  width: 300,
  height: 300,
  borderRightWidth: 100,
  borderRightColor: "#008480",
  borderBottomWidth: 100,
  borderBottomColor: "#006868",
  children: new Sprite({
    width: 200,
    height: 200,
    borderRightWidth: 100,
    borderRightColor: "#00baaf",
    borderBottomWidth: 100,
    borderBottomColor: "#009b9a",
    children: new Sprite({
      width: 100,
      height: 100,
      bgColor: "#00cfcd",
    }),
  }),
});

app.append(root);
```

# nodes

1. Sprite
2. Scrollbox
3. Input
4. Label

# Sprite

## attributes

tips: with "?" mark this field as optional

| name               | value                              | describe                                                                                                                                                                                       |
| ------------------ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id?                | string                             | id selector, the only one in the document                                                                                                                                                      |
| x?                 | number                             | In absolute layout, x is the X-axis offset relative to the upper left corner of the parent node. In a fixed layout, x is the X-axis offset relative to the upper-left corner of the Root node. |
| y?                 | number                             | with x 👆                                                                                                                                                                                      |
| width              | number                             |                                                                                                                                                                                                |
| height             | number                             |                                                                                                                                                                                                |
| bgColor?           | color string                       | either bgImage or bgColor                                                                                                                                                                      |
| bgImage?           | image url                          | either bgImage or bgColor, note the CROS                                                                                                                                                       |
| overflowY?         | hidden or visible                  | default: hidden                                                                                                                                                                                |
| overflowX?         | hidden or visible                  | default: hidden                                                                                                                                                                                |
| children?          | Array<Sprite \| Label \| Function> | child nodes                                                                                                                                                                                    |
| borderLeftColor?   | color string                       |                                                                                                                                                                                                |
| borderLeftWidth?   | number                             |                                                                                                                                                                                                |
| borderTopColor?    | color string                       |                                                                                                                                                                                                |
| borderTopWidth?    | number                             |                                                                                                                                                                                                |
| borderRightColor?  | color string                       |                                                                                                                                                                                                |
| borderRightWidth?  | number                             |                                                                                                                                                                                                |
| borderBottomColor? | color string                       |                                                                                                                                                                                                |
| borderBottomWidth? | number                             |                                                                                                                                                                                                |
| className?         | string or string[]                 | class selector                                                                                                                                                                                 |
| position?          | absolute or fixed                  | absolute: positioning relative to the parent; fixed: location relative to Root                                                                                                                 |
| visible?           | boolean                            | show and hide                                                                                                                                                                                  |
| zIndex?            | number                             | drawing order; default: 0                                                                                                                                                                      |

## methods:

| name                   | argument                                      | describe                                                                                                   |
| ---------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| on                     | (eventname: string, callback: Function)       | binding event; callback arguments: (this, event)                                                           |
| off                    | (eventname: string, callback: Function)       | unbinding event                                                                                            |
| append                 | (node: Sprite \| Input \| Scrollbox \| Label) | insert child node                                                                                          |
| remove                 | (node: Sprite \| Input \| Scrollbox \| Label) | remove child node                                                                                          |
| getElementById         | (id: string)                                  | returns the node or null                                                                                   |
| getElementsByClassName | (class: string)                               | returns the nodes or null                                                                                  |
| attr                   | (firstArgv: string \| object, value?: any)    | Modify the attribute value. If properties are not modified using this method, rendering may not be updated |

# Label

## attributes

tips: with "?" mark this field as optional

| name            | value                         | describe |
| --------------- | ----------------------------- | -------- |
| text?           | string                        |          |
| color?          | color string                  |          |
| fontFamily?     | string                        |          |
| bold?           | boolean                       |          |
| fontSize?       | number                        |
| stroke? boolean |                               |
| lineHeight?     | number                        |          |
| textAlign?      | "left" or "center" or "right" |          |
| underLine?      | color string                  |          |

## methods

| name                   | argument                                   | describe                                                                                                   |
| ---------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| getElementById         | (id: string)                               | returns the node or null                                                                                   |
| getElementsByClassName | (class: string)                            | returns the nodes or null                                                                                  |
| attr                   | (firstArgv: string \| object, value?: any) | Modify the attribute value. If properties are not modified using this method, rendering may not be updated |

# Input

## attributes

tips: with "?" mark this field as optional

| name               | value                              | describe                                                                                                                                                                                       |
| ------------------ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| placeholder?       | string                             |                                                                                                                                                                                                |
| value?             | string                             |                                                                                                                                                                                                |
| id?                | string                             | id selector, the only one in the document                                                                                                                                                      |
| x?                 | number                             | In absolute layout, x is the X-axis offset relative to the upper left corner of the parent node. In a fixed layout, x is the X-axis offset relative to the upper-left corner of the Root node. |
| y?                 | number                             | with x 👆                                                                                                                                                                                      |
| width              | number                             |                                                                                                                                                                                                |
| height             | number                             |                                                                                                                                                                                                |
| bgColor?           | color string                       | either bgImage or bgColor                                                                                                                                                                      |
| bgImage?           | image url                          | either bgImage or bgColor, note the CROS                                                                                                                                                       |
| overflowY?         | hidden or visible                  | default: hidden                                                                                                                                                                                |
| overflowX?         | hidden or visible                  | default: hidden                                                                                                                                                                                |
| children?          | Array<Sprite \| Label \| Function> | child nodes                                                                                                                                                                                    |
| borderLeftColor?   | color string                       |                                                                                                                                                                                                |
| borderLeftWidth?   | number                             |                                                                                                                                                                                                |
| borderTopColor?    | color string                       |                                                                                                                                                                                                |
| borderTopWidth?    | number                             |                                                                                                                                                                                                |
| borderRightColor?  | color string                       |                                                                                                                                                                                                |
| borderRightWidth?  | number                             |                                                                                                                                                                                                |
| borderBottomColor? | color string                       |                                                                                                                                                                                                |
| borderBottomWidth? | number                             |                                                                                                                                                                                                |
| className?         | string or string[]                 | class selector                                                                                                                                                                                 |
| position?          | absolute or fixed                  | absolute: positioning relative to the parent; fixed: location relative to Root                                                                                                                 |
| visible?           | boolean                            | show and hide                                                                                                                                                                                  |
| zIndex?            | number                             | drawing order; default: 0                                                                                                                                                                      |

## methods:

| name                   | argument                                   | describe                                                                                                   |
| ---------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| on                     | (eventname: string, callback: Function)    | binding event; callback arguments: (this, event)                                                           |
| off                    | (eventname: string, callback: Function)    | unbinding event                                                                                            |
| getElementById         | (id: string)                               | returns the node or null                                                                                   |
| getElementsByClassName | (class: string)                            | returns the nodes or null                                                                                  |
| attr                   | (firstArgv: string \| object, value?: any) | Modify the attribute value. If properties are not modified using this method, rendering may not be updated |

# Scrollbox

## attributes

tips: with "?" mark this field as optional

| name               | value                              | describe                                                                                                                                                                                       |
| ------------------ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| contentWidth       | number                             | content area width                                                                                                                                                                             |
| contentHeight      | number                             | content area height                                                                                                                                                                            |
| id?                | string                             | id selector, the only one in the document                                                                                                                                                      |
| x?                 | number                             | In absolute layout, x is the X-axis offset relative to the upper left corner of the parent node. In a fixed layout, x is the X-axis offset relative to the upper-left corner of the Root node. |
| y?                 | number                             | with x 👆                                                                                                                                                                                      |
| width              | number                             |                                                                                                                                                                                                |
| height             | number                             |                                                                                                                                                                                                |
| bgColor?           | color string                       | either bgImage or bgColor                                                                                                                                                                      |
| bgImage?           | image url                          | either bgImage or bgColor, note the CROS                                                                                                                                                       |
| overflowY?         | hidden or visible                  | default: hidden                                                                                                                                                                                |
| overflowX?         | hidden or visible                  | default: hidden                                                                                                                                                                                |
| children?          | Array<Sprite \| Label \| Function> | child nodes                                                                                                                                                                                    |
| borderLeftColor?   | color string                       |                                                                                                                                                                                                |
| borderLeftWidth?   | number                             |                                                                                                                                                                                                |
| borderTopColor?    | color string                       |                                                                                                                                                                                                |
| borderTopWidth?    | number                             |                                                                                                                                                                                                |
| borderRightColor?  | color string                       |                                                                                                                                                                                                |
| borderRightWidth?  | number                             |                                                                                                                                                                                                |
| borderBottomColor? | color string                       |                                                                                                                                                                                                |
| borderBottomWidth? | number                             |                                                                                                                                                                                                |
| className?         | string or string[]                 | class selector                                                                                                                                                                                 |
| position?          | absolute or fixed                  | absolute: positioning relative to the parent; fixed: location relative to Root                                                                                                                 |
| visible?           | boolean                            | show and hide                                                                                                                                                                                  |
| zIndex?            | number                             | drawing order; default: 0                                                                                                                                                                      |

## methods:

| name                   | argument                                      | describe                                                                                                   |
| ---------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| on                     | (eventname: string, callback: Function)       | binding event; callback arguments: (this, event)                                                           |
| off                    | (eventname: string, callback: Function)       | unbinding event                                                                                            |
| append                 | (node: Sprite \| Label \| Input \| Scrollbox) | insert child node                                                                                          |
| remove                 | (node: Sprite \| Label \| Input \| Scrollbox) | remove child node                                                                                          |
| getElementById         | (id: string)                                  | returns the node or null                                                                                   |
| getElementsByClassName | (class: string)                               | returns the nodes or null                                                                                  |
| attr                   | (firstArgv: string \| object, value: any)     | Modify the attribute value. If properties are not modified using this method, rendering may not be updated |

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