@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
129 lines (128 loc) • 4.67 kB
TypeScript
import { Font, IFonts } from "../helpers";
/**
* Interface representing the FontsManager.
*/
export interface IFontsManager {
/**
* A map storing fonts with their family and weight as the key.
*/
map: Map<string, Font>;
/**
* Whether debugging is enabled.
*/
debug: boolean;
}
/**
* Class representing a manager for handling fonts.
*/
export declare class FontsManager implements IFontsManager {
/**
* A map storing fonts with their family and weight as the key.
*/
map: Map<string, Font>;
/**
* Whether debugging is enabled.
*/
debug: boolean;
/**
* Constructs a new FontsManager instance.
* @param opts {Object} - Optional settings for the FontsManager.
* @param opts.debug {boolean} - Whether debugging is enabled.
*/
constructor(opts?: {
debug?: boolean;
});
/**
* Loads fonts into the manager from a given font list.
* @param fontList {IFonts} - The fonts to load into the manager.
* @returns {this} The current instance for chaining.
*/
loadFonts(fontList: IFonts): this;
/**
* Replace base fonts with custom fonts by special file.
* Use this method before loading fonts by `FontManager`.
* The file should be generated by the following instructions in MD file.
* @see https://github.com/NMMTY/LazyCanvas/blob/main/scripts/FontsGenerate.md
* @param fonts {Font[]} - The fonts to add to the manager.
* @returns {this} The current instance for chaining.
* @throws {LazyError} If required font properties are missing or the font already exists.
*/
add(...fonts: Font[]): this;
/**
* Removes fonts from the manager.
* @param array {Array<{ family: string, weight: string }>} - The family and weight of the fonts to remove.
* @returns {this} The current instance for chaining.
*/
remove(...array: Array<{
family: string;
weight: string;
}>): this;
/**
* Clears all fonts from the manager.
* @returns {this} The current instance for chaining.
*/
clear(): this;
/**
* Retrieves a font or fonts from the manager.
* @param family {string} - The family of the font to retrieve.
* @param weight {string} - The weight of the font to retrieve (optional).
* @returns {Font | Font[] | undefined} The retrieved font(s) or undefined if not found.
*/
get(family: string, weight?: string): Font | Font[] | undefined;
/**
* Checks if a font exists in the manager.
* @param family {string} - The family of the font to check.
* @param weight {string} - The weight of the font to check (optional).
* @returns {boolean} True if the font exists, false otherwise.
*/
has(family: string, weight?: string): boolean;
/**
* Retrieves the number of fonts in the manager.
* @returns {number} The size of the font map.
*/
size(): number;
/**
* Retrieves the values (fonts) from the manager.
* @returns {IterableIterator<Font>} An iterator for the font values.
*/
values(): IterableIterator<Font>;
/**
* Retrieves the keys (family and weight) from the manager.
* @returns {IterableIterator<string>} An iterator for the font keys.
*/
keys(): IterableIterator<string>;
/**
* Retrieves the entries (key-value pairs) from the manager.
* @returns {IterableIterator<[string, Font]>} An iterator for the font entries.
*/
entries(): IterableIterator<[string, Font]>;
/**
* Iterates over the fonts in the manager.
* @param callbackfn {Function} - The function to execute on each font.
* @param thisArg {any} - The `this` context to use (optional).
* @returns {this} The current instance for chaining.
*/
forEach(callbackfn: (value: Font, key: string, map: Map<string, Font>) => void, thisArg?: any): this;
/**
* Converts the font map to a JSON object.
* @returns {object} The JSON representation of the font map.
*/
toJSON(): object;
/**
* Populates the font map from a JSON object.
* @param json {object} - The JSON object to populate the map from.
* @returns {this} The current instance for chaining.
*/
fromJSON(json: object): this;
/**
* Converts the font map to an array.
* @returns {Font[]} An array of fonts.
*/
toArray(): Font[];
/**
* Populates the font map from an array of fonts.
* @param array {Font[]} - The array of fonts to populate the map from.
* @returns {this} The current instance for chaining.
*/
fromArray(array: Font[]): this;
}