1.1.2 • Published 2 years ago

elem-canvas v1.1.2

Weekly downloads
-
License
MIT License
Repository
github
Last release
2 years ago

el-canvas

Canvas rendering library, Sprite manipulation of canvas

hello world

<div id="app"></div>
  yarn add elem-canvas

    or

  npm i elem-canvas
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

namevaluedescribe
id?stringid selector, the only one in the document
x?numberIn 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?numberwith x 👆
widthnumber
heightnumber
bgColor?color stringeither bgImage or bgColor
bgImage?image urleither bgImage or bgColor, note the CROS
overflowY?hidden or visibledefault: hidden
overflowX?hidden or visibledefault: 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 fixedabsolute: positioning relative to the parent; fixed: location relative to Root
visible?booleanshow and hide
zIndex?numberdrawing order; default: 0

methods:

nameargumentdescribe
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

namevaluedescribe
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

nameargumentdescribe
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

namevaluedescribe
placeholder?string
value?string
id?stringid selector, the only one in the document
x?numberIn 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?numberwith x 👆
widthnumber
heightnumber
bgColor?color stringeither bgImage or bgColor
bgImage?image urleither bgImage or bgColor, note the CROS
overflowY?hidden or visibledefault: hidden
overflowX?hidden or visibledefault: 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 fixedabsolute: positioning relative to the parent; fixed: location relative to Root
visible?booleanshow and hide
zIndex?numberdrawing order; default: 0

methods:

nameargumentdescribe
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

namevaluedescribe
contentWidthnumbercontent area width
contentHeightnumbercontent area height
id?stringid selector, the only one in the document
x?numberIn 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?numberwith x 👆
widthnumber
heightnumber
bgColor?color stringeither bgImage or bgColor
bgImage?image urleither bgImage or bgColor, note the CROS
overflowY?hidden or visibledefault: hidden
overflowX?hidden or visibledefault: 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 fixedabsolute: positioning relative to the parent; fixed: location relative to Root
visible?booleanshow and hide
zIndex?numberdrawing order; default: 0

methods:

nameargumentdescribe
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
1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago