https://github.com/dmnsgn/canvas-context
Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, gpupresent), optionally offscreen for possible use in a Worker.
https://github.com/dmnsgn/canvas-context
2d bitmaprenderer canvas context experimental-webgl gpupresent offscreen webgl webgl2 worker
Last synced: 4 months ago
JSON representation
Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, gpupresent), optionally offscreen for possible use in a Worker.
- Host: GitHub
- URL: https://github.com/dmnsgn/canvas-context
- Owner: dmnsgn
- License: mit
- Created: 2019-02-04T21:10:11.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-07-06T15:18:29.000Z (about 1 year ago)
- Last Synced: 2025-03-10T13:02:23.153Z (4 months ago)
- Topics: 2d, bitmaprenderer, canvas, context, experimental-webgl, gpupresent, offscreen, webgl, webgl2, worker
- Language: HTML
- Homepage: https://dmnsgn.github.io/canvas-context/
- Size: 1.53 MB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# canvas-context
[](https://www.npmjs.com/package/canvas-context)
[](https://www.npmjs.com/package/canvas-context)
[](https://bundlephobia.com/package/canvas-context)
[](https://github.com/dmnsgn/canvas-context/blob/master/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/dmnsgn/canvas-context/blob/master/LICENSE)Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu), optionally offscreen for possible use in a Worker.
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)
See the [example](https://dmnsgn.github.io/canvas-context/) and its [source](index.html) with a Worker implementation.
## Installation
```bash
npm install canvas-context
```## Usage
```js
import createCanvasContext from "canvas-context";const { context, canvas } = createCanvasContext("2d", {
width: 100,
height: 100,
offscreen: true,
});
```## API
## Modules
## Typedefs
-
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.
-
CanvasContextOptions :object
-
Options for canvas creation. All optional.
-
CanvasContextReturnValue :object
## createCanvasContext
### createCanvasContext([contextType], [options]) ⇒ [CanvasContextReturnValue
](#CanvasContextReturnValue) ⏏
Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu), optionally offscreen for possible use in a Worker.
**Kind**: Exported function
| Param | Type | Default |
| ------------- | ---------------------------------------------------------- | --------------------------- |
| [contextType] | [ContextType
](#ContextType) | "2d"
|
| [options] | [CanvasContextOptions
](#CanvasContextOptions) | {}
|
## 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.
## CanvasContextOptions : object
Options for canvas creation. All optional.
**Kind**: global typedef
**Properties**
| Name | Type | Default | Description |
| ------------------- | ------------------------------------------------------------------------------------ | ------------------ | -------------------------------------- |
| [width] | number
| 300
| Request an initial canvas width. |
| [height] | number
| 150
| Request an initial canvas height. |
| [offscreen] | boolean
| false
| Request an offscreen canvas. |
| [worker] | boolean
| false
| Handle use in a worker. |
| [contextAttributes] | CanvasRenderingContext2DSettings
\| WebGLContextAttributes
| {}
| Attributes to be passed to getContext. |
## CanvasContextReturnValue : object
**Kind**: global typedef
**Properties**
| Name | Type |
| ------- | -------------------------------------------------------------- |
| canvas | HTMLCanvasElement
\| OffscreenCanvas
|
| context | RenderingContext
|
## License
MIT. See [license file](LICENSE.md).