@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
53 lines (52 loc) • 2.19 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { IOLazyCanvas, LazyCanvas } from "../LazyCanvas";
import { AnyExport } from "../../types";
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
/**
* Class responsible for exporting a LazyCanvas instance to various formats.
*/
export declare class Exporter {
/**
* The LazyCanvas instance to be exported.
*/
canvas: LazyCanvas;
/**
* Constructs a new Exporter instance.
* @param canvas {LazyCanvas} - The LazyCanvas instance to be exported.
*/
constructor(canvas: LazyCanvas);
/**
* Saves a file to the filesystem.
* @param buffer {any} - The data to be saved.
* @param extension {Extensions} - The file extension.
* @param name {string} - The name of the file (optional).
* @throws {LazyError} If the buffer or extension is not provided.
*/
private saveFile;
/**
* Exports all layers from the LayersManager as an array of JSON objects.
* @param manager {LayersManager} - The LayersManager instance.
* @returns {any[]} An array of JSON representations of the layers.
*/
private exportLayers;
/**
* Exports the canvas to the specified format.
* @param exportType {AnyExport} - The type of export (e.g., "png", "json").
* @param opts {Object} - Optional settings.
* @param opts.name {string} - The name of the file (optional).
* @param opts.saveAsFile {boolean} - Whether to save the export as a file (optional).
* @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
* @throws {LazyError} If the export type is not supported.
*/
export(exportType: AnyExport, opts?: {
name?: string;
saveAsFile?: boolean;
}): Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>;
/**
* Synchronously exports the canvas to the specified format.
* @param exportType {AnyExport} - The type of export (e.g., "json").
* @returns {IOLazyCanvas | void} The exported data or void if the export type is unsupported.
*/
syncExport(exportType: AnyExport): IOLazyCanvas | void;
}