UNPKG

@nmmty/lazycanvas

Version:

A simple way to interact with @napi-rs/canvas in an advanced way!

158 lines (157 loc) 4.78 kB
import { AnyCentring, AnyGradientType, FillType, StringColorType, ScaleType } from "../../types"; import { SKRSContext2D } from "@napi-rs/canvas"; import { LayersManager } from "../managers"; /** * Interface representing a gradient. */ export interface IGradient { /** * The type of fill, which is always `Gradient` for this interface. */ fillType: FillType; /** * The type of gradient (e.g., linear, radial, conic). */ type: AnyGradientType; /** * The points defining the gradient. */ points: Array<GradientPoint>; /** * The color stops for the gradient. */ stops: Array<GradientColorStop>; /** * The angle of the gradient (optional, used for linear gradients). */ angle?: number; } /** * Interface representing a color stop in a gradient. */ export interface GradientColorStop { /** * The color of the stop in hexadecimal format. */ color: StringColorType; /** * The offset of the stop, ranging from 0 to 1. */ offset: number; } /** * Interface representing a point in a gradient. */ export interface GradientPoint { /** * The x-coordinate of the point. */ x: ScaleType; /** * The y-coordinate of the point. */ y: ScaleType; /** * The radius of the point (optional, used for radial gradients). */ r?: number; } /** * Class representing a gradient with properties and methods to manipulate it. */ export declare class Gradient implements IGradient { /** * The type of fill, which is always `Gradient`. */ fillType: FillType; /** * The type of gradient (e.g., linear, radial, conic). */ type: AnyGradientType; /** * The points defining the gradient. */ points: Array<GradientPoint>; /** * The color stops for the gradient. */ stops: Array<GradientColorStop>; /** * The angle of the gradient (optional, used for linear gradients). */ angle?: number; /** * Constructs a new Gradient instance. * @param {Object} [opts] - Optional properties for the gradient. * @param {IGradient} [opts.props] - The gradient properties. */ constructor(opts?: { props?: IGradient; }); /** * Sets the type of the gradient. * @param {AnyGradientType} [type] - The type of the gradient (e.g., linear, radial, conic). * @returns {this} The current instance for chaining. */ setType(type: AnyGradientType): this; /** * Adds points to the gradient. * @param {GradientPoint[]} [points] - The points to add to the gradient. * @returns {this} The current instance for chaining. */ addPoints(...points: GradientPoint[]): this; /** * Sets the points of the gradient. * @param {GradientPoint[]} [points] - The points to set for the gradient. * @returns {this} The current instance for chaining. */ setPoints(...points: GradientPoint[]): this; /** * Removes points from the gradient by their indexes. * @param {number[]} [indexes] - The indexes of the points to remove. * @returns {this} The current instance for chaining. */ removePoints(...indexes: number[]): this; /** * Adds color stops to the gradient. * @param {GradientColorStop[]} [stops] - The color stops to add to the gradient. * @returns {this} The current instance for chaining. */ addStops(...stops: GradientColorStop[]): this; /** * Sets the color stops of the gradient. * @param {GradientColorStop[]} [stops] - The color stops to set for the gradient. * @returns {this} The current instance for chaining. */ setStops(...stops: GradientColorStop[]): this; /** * Removes color stops from the gradient by their indexes. * @param {number[]} [indexes] - The indexes of the color stops to remove. * @returns {this} The current instance for chaining. */ removeStops(...indexes: number[]): this; /** * Sets the angle of the gradient (used for linear gradients). * @param {number} [angle] - The angle in degrees. * @returns {this} The current instance for chaining. */ setAngle(angle: number): this; draw(ctx: SKRSContext2D, opts?: { debug?: boolean; layer?: { width: number; height: number; x: number; y: number; align: AnyCentring; }; manager?: LayersManager; }): CanvasGradient; /** * Converts the gradient to a JSON representation. * @returns {IGradient} The JSON representation of the gradient. */ toJSON(): IGradient; private getLinearGradientPoints; private getPosition; }