UNPKG

@nmmty/lazycanvas

Version:

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

116 lines (115 loc) 3.24 kB
import { AnyGradientType, FillType, StringColorType } from "../../types"; import { SKRSContext2D } from "@napi-rs/canvas"; /** * 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>; } /** * 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: number; /** * The y-coordinate of the point. */ y: number; /** * The radius of the point (optional, used for radial gradients). */ r?: number; /** * The starting angle of the point (optional, used for conic gradients). */ startAngle?: 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>; /** * Constructs a new Gradient instance. * @param opts {Object} - Optional properties for the gradient. * @param opts.props {IGradient} - The gradient properties. */ constructor(opts?: { props?: IGradient; }); /** * Sets the type of the gradient. * @param type {AnyGradientType} - 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 points {GradientPoint[]} - The points to add to the gradient. * @returns {this} The current instance for chaining. */ addPoints(...points: GradientPoint[]): this; /** * Adds color stops to the gradient. * @param stops {GradientColorStop[]} - The color stops to add to the gradient. * @returns {this} The current instance for chaining. */ addStops(...stops: GradientColorStop[]): this; /** * Draws the gradient on a canvas context. * @param ctx {SKRSContext2D} - The canvas rendering context. * @returns {CanvasGradient} The created gradient. */ draw(ctx: SKRSContext2D): CanvasGradient; /** * Converts the gradient to a JSON representation. * @returns {IGradient} The JSON representation of the gradient. */ toJSON(): IGradient; }