@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
71 lines (70 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Link = void 0;
const types_1 = require("../../types");
/**
* Class representing a link between layers with properties and methods to manipulate it.
*/
class Link {
/**
* The source layers ID.
*/
source;
/**
* The type of the link (e.g., width, height, etc.).
*/
type;
/**
* The additional spacing applied to the link.
*/
additionalSpacing;
/**
* Constructs a new Link instance.
* @param opts {Object} - Optional properties for the link.
* @param opts.props {ILink} - The link properties.
*/
constructor(opts) {
this.source = opts?.props?.source || '';
this.type = opts?.props?.type || types_1.LinkType.Width;
this.additionalSpacing = opts?.props?.additionalSpacing || 0;
}
/**
* Sets the source of the link.
* @param source {string} - The ID of the layer to link.
* @returns {this} The current instance for chaining.
*/
setSource(source) {
this.source = source;
return this;
}
/**
* Sets the type of the link.
* @param type {AnyLinkType} - The type of the link.
* @returns {this} The current instance for chaining.
*/
setType(type) {
this.type = type;
return this;
}
/**
* Sets the additional spacing of the link.
* @param additionalSpacing {ScaleType} - The additional spacing of the link.
* @returns {this} The current instance for chaining.
*/
setSpacing(additionalSpacing) {
this.additionalSpacing = additionalSpacing;
return this;
}
/**
* Converts the Link instance to a JSON representation.
* @returns {ILink} The JSON representation of the link.
*/
toJSON() {
return {
source: this.source,
type: this.type,
additionalSpacing: this.additionalSpacing
};
}
}
exports.Link = Link;