@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
175 lines (174 loc) • 5.54 kB
TypeScript
import { AnyExport, JSONLayer } from "../types";
import { Canvas, SKRSContext2D, SvgCanvas, SvgExportFlag } from "@napi-rs/canvas";
import { LayersManager, RenderManager, FontsManager, AnimationManager, IAnimationOptions, PluginManager, ILazyCanvasPlugin } from "./managers";
import { Group } from "./components";
/**
* Interface representing the LazyCanvas structure.
*/
export interface ILazyCanvas {
/**
* The canvas instance, which can be either a Canvas or SvgCanvas.
*/
canvas: Canvas | SvgCanvas;
/**
* The 2D rendering context of the canvas.
*/
ctx: SKRSContext2D;
/**
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
*/
manager: {
layers: LayersManager;
render: RenderManager;
fonts: FontsManager;
animation: AnimationManager;
plugins: PluginManager;
};
/**
* The options for configuring the LazyCanvas instance.
*/
options: ILazyCanvasOptions;
}
/**
* Interface representing the options for LazyCanvas.
*/
export interface ILazyCanvasOptions {
/**
* The width of the canvas.
*/
width: number;
/**
* The height of the canvas.
*/
height: number;
/**
* Whether the canvas is animated.
*/
animated: boolean;
/**
* The export type for the canvas (e.g., buffer, SVG, etc.).
*/
exportType: AnyExport;
/**
* The SVG export flag for encoding paths.
*/
flag: SvgExportFlag;
}
/**
* Interface representing the input options for LazyCanvas.
*/
export interface IOLazyCanvas {
/**
* The options for configuring the LazyCanvas instance.
*/
options: ILazyCanvasOptions;
/**
* The animation options for the LazyCanvas instance.
*/
animation: IAnimationOptions;
/**
* The layers to be added to the LazyCanvas instance.
*/
layers: Array<JSONLayer | Group>;
}
/**
* Class representing a LazyCanvas, which provides a structured way to manage canvas rendering.
*/
export declare class LazyCanvas implements ILazyCanvas {
/**
* The canvas instance, which can be either a Canvas or SvgCanvas.
*/
canvas: Canvas | SvgCanvas;
/**
* The 2D rendering context of the canvas.
*/
ctx: SKRSContext2D;
/**
* The manager object containing various managers for layers, rendering, fonts, and animation.
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
*/
manager: {
layers: LayersManager;
render: RenderManager;
fonts: FontsManager;
animation: AnimationManager;
plugins: PluginManager;
};
/**
* The options for configuring the LazyCanvas instance.
*/
options: ILazyCanvasOptions;
/**
* Constructs a new LazyCanvas instance.
* @param {Object} [opts] - Optional settings for the LazyCanvas instance.
* @param {boolean} [opts.debug] - Whether debugging is enabled.
* @param {IOLazyCanvas} [opts.settings] - The input settings for the LazyCanvas instance.
*/
constructor(opts?: {
debug?: boolean;
settings?: IOLazyCanvas;
});
/**
* Sets the export type for the canvas.
* @param {AnyExport} [type] - The export type (e.g., buffer, SVG, etc.).
* @returns {this} The current instance for chaining.
*/
setExportType(type: AnyExport): this;
/**
* Sets the SVG export flag. This method should be called after `setExportType`.
* @param {SvgExportFlag} [flag] - The SVG export flag.
* @returns {this} The current instance for chaining.
*/
setSvgExportFlag(flag: SvgExportFlag): this;
/**
* Enables animation for the canvas.
* @returns {this} The current instance for chaining.
*/
animated(): this;
/**
* Resizes the canvas to the specified dimensions.
* @param {number} [ratio] - The ratio to resize the canvas.
* @returns {this} The current instance for chaining.
*/
resize(ratio: number): this;
/**
* Creates a new canvas with the specified dimensions.
* @param {number} [width] - The width of the canvas.
* @param {number} [height] - The height of the canvas.
* @returns {this} The current instance for chaining.
*/
create(width: number, height: number): this;
/**
* Installs a plugin to the canvas.
* @param {ILazyCanvasPlugin} [plugin] - The plugin to install.
* @returns {this} The current instance for chaining.
*/
use(plugin: ILazyCanvasPlugin): this;
/**
* Removes a plugin from the canvas.
* @param {string} [pluginName] - The name of the plugin to remove.
* @returns {this} The current instance for chaining.
*/
removePlugin(pluginName: string): this;
/**
* Gets a plugin by name.
* @param {string} [pluginName] - The name of the plugin.
* @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
*/
getPlugin(pluginName: string): ILazyCanvasPlugin | undefined;
/**
* Lists all installed plugins.
* @returns {string[]} Array of plugin names.
*/
listPlugins(): string[];
/**
* Gets information about all installed plugins.
* @returns Array of plugin information objects.
*/
getPluginsInfo(): Array<{
name: string;
version: string;
description?: string;
dependencies?: string[];
}>;
}