Notoriously Psychedelic Modules

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

canvas-context

1.0.1 • Public • Published

canvas-context stable

npm version styled with prettier

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

See the demo and its source for an example with Worker implementation.

Installation

npm install canvas-context

NPM

Usage

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

API

createCanvasContext(contextType, options): { context: RenderingContext, canvas: HTMLCanvasElement }

type ContextType = 
    | "2d"
    | "webgl"
    | "experimental-webgl"
    | "webgl2"
    | "bitmaprenderer";
Option Type Default Description
contextType ContextType "2d" Context identifier defining the drawing context associated to the canvas
options.canvas HTMLCanvasElement? An optional canvas. Necessary when window === "undefined" (eg. Node or Worker context)
options.width number? 300 Set canvas.width (should be an integer >= 0)
options.height number? 150 Set canvas.height (should be an integer >= 0)
options.offscreen boolean? false Create an OffscreenCanvas or transferControlToOffscreen() if options.canvas
options.worker boolean? false Try to get an OffscreenCanvas and return only the canvas so it can be transferred in a Worker

License

MIT. See license file.

install

npm i canvas-context

Downloadsweekly downloads

7

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability