canvas-api-lite
v1.1.0
Published
An implementation of the Canvas API for use in non-browser contexts like Node.js.
Readme
canvas-api-lite
An implementation of the Canvas API for use in non-browser contexts like Node.js.
Unlike node-canvas, this implementation has no native dependencies. However, this library only implements a small subset of the Canvas API.
The intended use case is to port code that operated against ImageData / Canvas to platforms like Node.js.
Supported APIs
This module exports the following types with implemented features as noted.
CanvasRenderingContext2Dconstructor(canvas)canvasgetter propertysave/restorecreateImageDatasettingsargument not supported.
getImageDatasettingsargument not supported.
putImageDatadrawImage- Scaling of the drawn image is not supported. Consider using a separate library like
resize-image-datato scale prior to calling.
- Scaling of the drawn image is not supported. Consider using a separate library like
fillStyle- Limited color formats (see below)
clearRectfillRect
HTMLCanvasElementconstructor(width?, height?)- Non-standard. This is how you instantiate this type without
document.createElement.
- Non-standard. This is how you instantiate this type without
widthpropertyheightpropertygetContext"2d"parameter only
toDataURL- Limited to creating
image/pngURLs.
- Limited to creating
- DOM properties
id,outerHTML,innerHTML,tagNamehave very basic implementations. - Element constants like
ELEMENT_NODEare defined.
HTMLImageElement- The
Imagetype is provided to construct anHTMLImageElement. srcproperty- Currently limited to accepting PNG Data URLs.
widthgetter propertyheightgetter property- Same as
naturalWidth/naturalHeight.
- Same as
naturalWidthgetter propertynaturalHeightgetter propertycompletegetter propertyaddEventListenerremoveEventListenerload,errorevent types only.
- The
ImageDataconstructorsettingsargument not supported.- Both
widthandheightmust be passed. (Does not inferheightfromwidthand data array size.)
datagetter property- A
ImageDataArraytype alias forUint8ClampedArray<ArrayBuffer>is provided for this.
- A
widthgetter propertyheightgetter propertycolorSpacegetter property- Always
srgb.
- Always
Supported color formats
- Hex colors (
#RGB,#RGBA,#RRGGBB,#RRGGBBAA) - RGB colors (
rgb(255, 255, 255),rgba(255, 255, 255, 0.5)) - The ~150 standard CSS named colors.
