UNPKG

@nmmty/lazycanvas

Version:

A simple way to interact with @napi-rs/canvas in an advanced way!

71 lines (70 loc) 2.76 kB
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 {Object} [opts] - Optional settings for the RenderManager. * @param {boolean} [opts.debug] - Whether debugging is enabled. */ constructor(lazyCanvas: LazyCanvas, opts?: { debug?: boolean; }); /** * Merges multiple ImageData objects into a single ImageData object. * @param {SKRSContext2D} [ctx] - The canvas rendering context. * @param {ImageData[]} [imageDataList] - The list of ImageData objects to merge. * @param {number} [width] - The width of the resulting ImageData. * @param {number} [height] - The height of the resulting ImageData. * @returns {ImageData} The merged ImageData object. */ private mergeImageData; /** * Renders a single layer or group of layers. * @param {AnyLayer | Group} [layer] - 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 {AnyExport} [exportType] - 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 {AnyExport} [format] - 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>; }