UNPKG

pencil.js

Version:

Nice modular interactive 2D drawing library.

110 lines (109 loc) 3.4 kB
/** * @module OffscreenCanvas */ /** * Off-screen canvas class * @class */ export default class OffScreenCanvas extends Container { /** * Build a canvas context and returns it * @param {Number} width - Width of the canvas * @param {Number} height - Height of the canvas * @return {CanvasRenderingContext2D} */ static getDrawingContext(width?: number, height?: number): CanvasRenderingContext2D; /** * @typedef {Object} OffscreenCanvasOptions * @prop {String|Color} [fill=null] - Background color * @prop {Number} [opacity=1] - Global opacity */ /** * @type {OffscreenCanvasOptions} */ static get defaultOptions(): OffscreenCanvasOptions; /** * Off-screen canvas constructor * @param {Number} [width=1] - Width of the canvas * @param {Number} [height=1] - Height of the canvas * @param {ContainerOptions} [options] - Specific options */ constructor(width?: number, height?: number, options?: any); /** * @type {CanvasRenderingContext2D} */ ctx: CanvasRenderingContext2D; /** * Change the behavior for upscaled images, smoothing is good for pictures but bad for pixel-art * @param {Boolean} enable - Should the smoothing be active or not * @return {OffScreenCanvas} Itself */ setImageSmoothing(enable: boolean): OffScreenCanvas; /** * Erase the canvas * @return {OffScreenCanvas} Itself */ clear(): OffScreenCanvas; /** * @param {Number} width - New width value */ set width(arg: number); /** * @return {Number} */ get width(): number; /** * @param {Number} height - New height value */ set height(arg: number); /** * @return {Number} */ get height(): number; /** * Return the whole scene size * @return {Position} */ get size(): Position; /** * Return this scene center point * @return {Position} */ get center(): Position; /** * Return a random position within the scene * @return {Position} */ getRandomPosition(): Position; /** * Return the whole canvas as data * @param {VectorDefinition} [vectorDefinition] - Box of data to extract * @return {ImageData} */ getImageData(vectorDefinition?: any): ImageData; /** * Put data into the canvas * @param {ImageData} imageData - Data to add to the canvas * @param {PositionDefinition} [positionDefinition] - Position of the data */ setImageData(imageData: ImageData, positionDefinition?: any): void; /** * Return an image composed of its content * @param {VectorDefinition} [vectorDefinition] - Box to restrict exported data * @param {String} [type="image/png"] - Data format. Supported format depend on the browser implementation (png or jpeg are the only safe choices) * @return {HTMLImageElement} */ toImage(vectorDefinition?: any, type?: string): HTMLImageElement; } export type OffscreenCanvasOptions = { /** * - Background color */ fill?: string | any; /** * - Global opacity */ opacity?: number; }; import Container from "@pencil.js/container"; import Position from "@pencil.js/position";