@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
73 lines (72 loc) • 2.8 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { AnyExport } from "../../types";
import { LazyCanvas } from "../LazyCanvas";
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
/**
* Interface representing the RenderManager.
*/
export interface IRenderManager {
/**
* The LazyCanvas instance used for rendering.
*/
lazyCanvas: LazyCanvas;
/**
* Whether debugging is enabled.
*/
debug: boolean;
}
/**
* Class responsible for managing rendering operations, including static and animated exports.
*/
export declare class RenderManager implements IRenderManager {
/**
* The LazyCanvas instance used for rendering.
*/
lazyCanvas: LazyCanvas;
/**
* Whether debugging is enabled.
*/
debug: boolean;
/**
* Constructs a new RenderManager instance.
* @param lazyCanvas {LazyCanvas} - The LazyCanvas instance to use for rendering.
* @param opts {Object} - Optional settings for the RenderManager.
* @param opts.debug {boolean} - Whether debugging is enabled.
*/
constructor(lazyCanvas: LazyCanvas, opts?: {
debug?: boolean;
});
/**
* Merges multiple ImageData objects into a single ImageData object.
* @param ctx {SKRSContext2D} - The canvas rendering context.
* @param imageDataList {ImageData[]} - The list of ImageData objects to merge.
* @param width {number} - The width of the resulting ImageData.
* @param height {number} - The height of the resulting ImageData.
* @returns {ImageData} The merged ImageData object.
*/
private mergeImageData;
/**
* Renders a single layer or group of layers.
* @param layer {AnyLayer | Group} - The layer or group to render.
* @returns {Promise<SKRSContext2D>} The canvas rendering context after rendering.
*/
private renderLayer;
/**
* Renders all layers statically and exports the result in the specified format.
* @param exportType {AnyExport} - The export format (e.g., buffer, SVG, or context).
* @returns {Promise<Buffer | SKRSContext2D | string>} The rendered output in the specified format.
*/
private renderStatic;
/**
* Renders an animated sequence of layers and exports it as a GIF.
* @returns {Promise<Buffer>} The rendered animation as a Buffer.
*/
private renderAnimation;
/**
* Renders all layers and exports the result in the specified format.
* @param format {AnyExport} - The export format (e.g., buffer, context, SVG, or canvas).
* @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The rendered output in the specified format.
*/
render(format: AnyExport): Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>;
}