canvas-context
Advanced tools
Comparing version 2.0.0 to 3.0.0
24
index.js
@@ -0,1 +1,5 @@ | ||
/** | ||
* @module createCanvasContext | ||
*/ | ||
const contextTypeList = [ | ||
@@ -8,6 +12,14 @@ "2d", | ||
"bitmaprenderer", | ||
"gpupresent" | ||
"gpupresent", | ||
]; | ||
export default function createCanvasContext(contextType = "2d", options = {}) { | ||
/** | ||
* Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, gpupresent), optionally offscreen for possible use in a Worker. | ||
* | ||
* @alias module:createCanvasContext | ||
* @param {ContextType} [contextType="2d"] | ||
* @param {CanvasContextOptions} [options={}] | ||
* @returns {CanvasContextReturnValue} | ||
*/ | ||
function createCanvasContext(contextType = "2d", options = {}) { | ||
// Get options and set defaults | ||
@@ -18,6 +30,6 @@ const { | ||
offscreen = false, | ||
worker = false, | ||
contextAttributes = {}, | ||
worker = false | ||
} = { | ||
...options | ||
...options, | ||
}; | ||
@@ -63,4 +75,6 @@ | ||
canvas, | ||
context | ||
context, | ||
}; | ||
} | ||
export default createCanvasContext; |
@@ -1,2 +0,2 @@ | ||
Copyright (C) 2019 the internet and Damien Seguin | ||
Copyright (C) 2019 Damien Seguin | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "canvas-context", | ||
"version": "2.0.0", | ||
"description": "Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer), optionally offscreen for possible use in a Worker.", | ||
"main": "lib/canvas-context.cjs.js", | ||
"jsnext:main": "lib/canvas-context.esm.js", | ||
"module": "lib/canvas-context.esm.js", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"author": "Damien Seguin (https://dmnsgn.me)", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "rollup -c -w -m inline --environment NODE_ENV:development", | ||
"build": "rollup -c --environment NODE_ENV:production", | ||
"test": "npm run build", | ||
"clean": "rm -rf lib", | ||
"preversion": "npm run clean", | ||
"version": "npm run build && git add -A", | ||
"postversion": "git push origin master && git push --tags && npm publish" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.8.7", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.8.3", | ||
"@babel/preset-env": "^7.8.7", | ||
"rollup": "^2.0.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-serve": "^1.0.1", | ||
"rollup-plugin-terser": "^5.2.0" | ||
}, | ||
"version": "3.0.0", | ||
"description": "Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, gpupresent), optionally offscreen for possible use in a Worker.", | ||
"keywords": [ | ||
@@ -43,12 +15,27 @@ "canvas", | ||
"webgl2", | ||
"bitmaprenderer" | ||
"bitmaprenderer", | ||
"gpupresent" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/dmnsgn/canvas-context.git" | ||
}, | ||
"homepage": "https://github.com/dmnsgn/canvas-context", | ||
"bugs": { | ||
"url": "https://github.com/dmnsgn/canvas-context/issues" | ||
"bugs": "https://github.com/dmnsgn/canvas-context/issues", | ||
"repository": "dmnsgn/canvas-context", | ||
"funding": [ | ||
{ | ||
"type": "individual", | ||
"url": "https://paypal.me/dmnsgn" | ||
}, | ||
{ | ||
"type": "individual", | ||
"url": "https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3" | ||
} | ||
], | ||
"license": "MIT", | ||
"author": "Damien Seguin (https://github.com/dmnsgn)", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "types/index.d.ts", | ||
"engines": { | ||
"node": ">=15.0.0", | ||
"npm": ">=7.0.0" | ||
} | ||
} |
124
README.md
@@ -1,11 +0,22 @@ | ||
# canvas-context [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) | ||
# canvas-context | ||
[![npm version](https://badge.fury.io/js/canvas-context.svg)](https://www.npmjs.com/package/canvas-context) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
[![npm version](https://img.shields.io/npm/v/canvas-context)](https://www.npmjs.com/package/canvas-context) | ||
[![stability-stable](https://img.shields.io/badge/stability-stable-green.svg)](https://www.npmjs.com/package/canvas-context) | ||
[![npm minzipped size](https://img.shields.io/bundlephobia/minzip/canvas-context)](https://www.npmjs.com/package/canvas-context) | ||
[![dependencies](https://img.shields.io/david/dmnsgn/canvas-context)](https://github.com/dmnsgn/canvas-context/blob/master/package.json) | ||
[![types](https://img.shields.io/npm/types/canvas-context)](https://github.com/microsoft/TypeScript) | ||
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-fa6673.svg)](https://conventionalcommits.org) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-Prettier-f8bc45.svg?logo=prettier)](https://github.com/prettier/prettier) | ||
[![linted with eslint](https://img.shields.io/badge/linted_with-ES_Lint-4B32C3.svg?logo=eslint)](https://github.com/eslint/eslint) | ||
[![license](https://img.shields.io/github/license/dmnsgn/canvas-context)](https://github.com/dmnsgn/canvas-context/blob/master/LICENSE) | ||
Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer), optionally offscreen for possible use in a Worker. | ||
Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, gpupresent), optionally offscreen for possible use in a Worker. | ||
[![paypal](https://img.shields.io/badge/donate-paypal-informational?logo=paypal)](https://paypal.me/dmnsgn) | ||
[![coinbase](https://img.shields.io/badge/donate-coinbase-informational?logo=coinbase)](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3) | ||
[![twitter](https://img.shields.io/twitter/follow/dmnsgn?style=social)](https://twitter.com/dmnsgn) | ||
![](https://raw.githubusercontent.com/dmnsgn/canvas-context/master/screenshot.gif) | ||
See the [demo](https://dmnsgn.github.io/canvas-context/) and its [source](demo.js) for an example with Worker implementation. | ||
See the [example](https://dmnsgn.github.io/canvas-context/) and its [source](index.html) with a Worker implementation. | ||
@@ -18,13 +29,11 @@ ## Installation | ||
[![NPM](https://nodei.co/npm/canvas-context.png)](https://nodei.co/npm/canvas-context/) | ||
## Usage | ||
```js | ||
const createCanvasContext = require("canvas-context"); | ||
import createCanvasContext from "canvas-context"; | ||
const { context, canvas } = createCanvasContext("2d", { | ||
width: 100, | ||
height: 100, | ||
offscreen: true | ||
width: 100, | ||
height: 100, | ||
offscreen: true, | ||
}); | ||
@@ -35,24 +44,81 @@ ``` | ||
### `createCanvasContext(contextType, options): { context: RenderingContext, canvas: HTMLCanvasElement }` | ||
<!-- api-start --> | ||
```ts | ||
type ContextType = | ||
| "2d" | ||
| "webgl" | ||
| "experimental-webgl" | ||
| "webgl2" | ||
| "bitmaprenderer"; | ||
``` | ||
## Modules | ||
| 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 | | ||
<dl> | ||
<dt><a href="#module_createCanvasContext">createCanvasContext</a></dt> | ||
<dd></dd> | ||
</dl> | ||
## Typedefs | ||
<dl> | ||
<dt><a href="#ContextType">ContextType</a> : <code>"2d"</code> | <code>"webgl"</code> | <code>"experimental-webgl"</code> | <code>"webgl2"</code> | <code>"webgl2-compute"</code> | <code>"bitmaprenderer"</code> | <code>"gpupresent"</code></dt> | ||
<dd><p>A DOMString containing the context identifier defining the drawing context associated to the canvas.</p> | ||
</dd> | ||
<dt><a href="#CanvasContextOptions">CanvasContextOptions</a> : <code>Object</code></dt> | ||
<dd><p>Options for canvas creation. All optional.</p> | ||
</dd> | ||
<dt><a href="#CanvasContextReturnValue">CanvasContextReturnValue</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
</dl> | ||
<a name="module_createCanvasContext"></a> | ||
## createCanvasContext | ||
<a name="exp_module_createCanvasContext--createCanvasContext"></a> | ||
### createCanvasContext([contextType], [options]) ⇒ [<code>CanvasContextReturnValue</code>](#CanvasContextReturnValue) ⏏ | ||
Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, gpupresent), optionally offscreen for possible use in a Worker. | ||
**Kind**: Exported function | ||
| Param | Type | Default | | ||
| ------------- | ---------------------------------------------------------- | --------------------------- | | ||
| [contextType] | [<code>ContextType</code>](#ContextType) | <code>"2d"</code> | | ||
| [options] | [<code>CanvasContextOptions</code>](#CanvasContextOptions) | <code>{}</code> | | ||
<a name="ContextType"></a> | ||
## ContextType : <code>"2d"</code> \| <code>"webgl"</code> \| <code>"experimental-webgl"</code> \| <code>"webgl2"</code> \| <code>"webgl2-compute"</code> \| <code>"bitmaprenderer"</code> \| <code>"gpupresent"</code> | ||
A DOMString containing the context identifier defining the drawing context associated to the canvas. | ||
**Kind**: global typedef | ||
<a name="CanvasContextOptions"></a> | ||
## CanvasContextOptions : <code>Object</code> | ||
Options for canvas creation. All optional. | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | Default | Description | | ||
| ------------------- | ------------------------------------------------------------------------------------ | ------------------ | -------------------------------------- | | ||
| [width] | <code>number</code> | <code>300</code> | Request an initial canvas width. | | ||
| [height] | <code>number</code> | <code>150</code> | Request an initial canvas height. | | ||
| [offscreen] | <code>boolean</code> | <code>false</code> | Request an offscreen canvas. | | ||
| [worker] | <code>boolean</code> | <code>false</code> | Handle use in a worker. | | ||
| [contextAttributes] | <code>CanvasRenderingContext2DSettings</code> \| <code>WebGLContextAttributes</code> | <code>{}</code> | Attributes to be passed to getContext. | | ||
<a name="CanvasContextReturnValue"></a> | ||
## CanvasContextReturnValue : <code>Object</code> | ||
**Kind**: global typedef | ||
**Properties** | ||
| Name | Type | | ||
| ------- | -------------------------------------------------------------- | | ||
| canvas | <code>HTMLCanvasElement</code> \| <code>OffscreenCanvas</code> | | ||
| context | <code>RenderingContext</code> | | ||
<!-- api-end --> | ||
## License | ||
MIT. See [license file](https://github.com/dmnsgn/canvas-context/blob/master/LICENSE.md). | ||
MIT. See [license file](LICENSE.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13277
0
9
126
123
Yes
1
1