sketch-attach
TypeScript icon, indicating that this package has built-in type declarations

0.5.2 • Public • Published

Sketch-attach

npm

Attaches a canvas element to a container

Getting started

Install from npm

npm i -S sketch-attach

Provides a consistent optional API for attaching a canvas element to a container. It will create a canvas element if you do not supply one.

import {attach} from 'sketch-attach'

const canvas = document.createElement('canvas')
const {canvas, container} = attach({
  canvas: canvas,
  container: document.body,
})

API

const canvas = create(opts?)
  • canvas? HTMLCanvasElement
  • container? HTMLElement

Examples

Sketch smoothes out the experience of creating and rendering on to a canvas.

import {create as createCanvas} from 'sketch-canvas'
import {create as createContext} from 'sketch-context'
import {attach} from 'sketch-attach'

const canvas = createCanvas({
  width: 640,
  height: 480,
})
const ctx = createContext({canvas})
attach({canvas, container: document.body})

ctx.fillStyle = '#f7ce68'
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height)

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i sketch-attach

Weekly Downloads

0

Version

0.5.2

License

MIT

Unpacked Size

8.95 kB

Total Files

13

Last publish

Collaborators

  • mattstyles