@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
94 lines (93 loc) • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Font = void 0;
const types_1 = require("../../types");
/**
* Class representing a font with properties such as family, weight, path, and base64.
*/
class Font {
/**
* The font family.
*/
family;
/**
* The weight of the font.
*/
weight;
/**
* The file path of the font (optional).
*/
path;
/**
* The base64 representation of the font (optional).
*/
base64;
/**
* Constructs a new Font instance with default values.
*/
constructor() {
this.family = "Arial";
this.weight = types_1.FontWeight.Regular;
}
/**
* Sets the font family.
* @param family {string} - The `family` of the font.
* @returns {this} The current instance for chaining.
* @throws {Error} If the family is not provided.
*/
setFamily(family) {
if (!family)
throw new Error("Family must be provided");
this.family = family;
return this;
}
/**
* Sets the font weight.
* @param weight {AnyWeight} - The `weight` of the font.
* @returns {this} The current instance for chaining.
* @throws {Error} If the weight is not provided.
*/
setWeight(weight) {
if (!weight)
throw new Error("Weight must be provided");
this.weight = weight;
return this;
}
/**
* Sets the file path of the font.
* @param path {string} - The `path` of the font.
* @returns {this} The current instance for chaining.
* @throws {Error} If the path is not provided.
*/
setPath(path) {
if (!path)
throw new Error("Path must be provided");
this.path = path;
return this;
}
/**
* Sets the base64 representation of the font.
* @param base64 {Buffer} - The `base64` of the font.
* @returns {this} The current instance for chaining.
* @throws {Error} If the base64 is not provided.
*/
setBase64(base64) {
if (!base64)
throw new Error("Base64 must be provided");
this.base64 = base64;
return this;
}
/**
* Converts the Font instance to a JSON representation.
* @returns {IFont} The JSON representation of the font.
*/
toJSON() {
return {
family: this.family,
weight: this.weight,
path: this.path,
base64: this.base64
};
}
}
exports.Font = Font;