@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
142 lines (141 loc) • 4.33 kB
TypeScript
import { AnyExport, JSONLayer } from "../types";
import { Canvas, SKRSContext2D, SvgCanvas, SvgExportFlag } from "@napi-rs/canvas";
import { LayersManager } from "./managers/LayersManager";
import { RenderManager } from "./managers/RenderManager";
import { FontsManager } from "./managers/FontsManager";
import { AnimationManager, IAnimationOptions } from "./managers/AnimationManager";
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, and animation.
*/
manager: {
layers: LayersManager;
render: RenderManager;
fonts: FontsManager;
animation: AnimationManager;
};
/**
* 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.
*/
manager: {
layers: LayersManager;
render: RenderManager;
fonts: FontsManager;
animation: AnimationManager;
};
/**
* The options for configuring the LazyCanvas instance.
*/
options: ILazyCanvasOptions;
/**
* Constructs a new LazyCanvas instance.
* @param opts {Object} - Optional settings for the LazyCanvas instance.
* @param opts.debug {boolean} - Whether debugging is enabled.
* @param opts.settings {IOLazyCanvas} - The input settings for the LazyCanvas instance.
*/
constructor(opts?: {
debug?: boolean;
settings?: IOLazyCanvas;
});
/**
* Sets the export type for the canvas.
* @param type {AnyExport} - 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 flag {SvgExportFlag} - 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 ratio {number} - 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 width {number} - The width of the canvas.
* @param height {number} - The height of the canvas.
* @returns {this} The current instance for chaining.
*/
create(width: number, height: number): this;
}