3.2.0 • Published 2 years ago

canvas-context v3.2.0

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

canvas-context

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu), optionally offscreen for possible use in a Worker.

paypal coinbase twitter

npm.io

See the example and its source with a Worker implementation.

Installation

npm install canvas-context

Usage

import createCanvasContext from "canvas-context";

const { context, canvas } = createCanvasContext("2d", {
  width: 100,
  height: 100,
  offscreen: true,
});

API

Modules

Typedefs

createCanvasContext

createCanvasContext(contextType, options) ⇒ CanvasContextReturnValue

Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu), optionally offscreen for possible use in a Worker.

Kind: Exported function

ParamTypeDefault
contextTypeContextType"2d"
optionsCanvasContextOptions{}

ContextType : "2d" | "webgl" | "experimental-webgl" | "webgl2" | "webgl2-compute" | "bitmaprenderer" | "gpupresent" | "webgpu"

A DOMString containing the context identifier defining the drawing context associated to the canvas.

Kind: global typedef

CanvasContextOptions : Object

Options for canvas creation. All optional.

Kind: global typedef Properties

NameTypeDefaultDescription
widthnumber300Request an initial canvas width.
heightnumber150Request an initial canvas height.
offscreenbooleanfalseRequest an offscreen canvas.
workerbooleanfalseHandle use in a worker.
contextAttributesCanvasRenderingContext2DSettings | WebGLContextAttributes{}Attributes to be passed to getContext.

CanvasContextReturnValue : Object

Kind: global typedef Properties

NameType
canvasHTMLCanvasElement | OffscreenCanvas
contextRenderingContext

License

MIT. See license file.