UNPKG

@nmmty/lazycanvas

Version:

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

69 lines (68 loc) 2.25 kB
import { FillType, AnyPatternType } from "../../types"; import { LazyCanvas } from "../LazyCanvas"; import { SKRSContext2D } from "@napi-rs/canvas"; /** * Interface representing a pattern. */ export interface IPattern { /** * The type of fill, which is always `Pattern` for this interface. */ fillType: FillType; /** * The type of the pattern (e.g., repeat, no-repeat, etc.). */ type: AnyPatternType; /** * The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance. */ src: string | LazyCanvas; } /** * Class representing a pattern with properties and methods to manipulate it. */ export declare class Pattern implements IPattern { /** * The type of fill, which is always `Pattern`. */ fillType: FillType; /** * The type of the pattern (e.g., repeat, no-repeat, etc.). */ type: AnyPatternType; /** * The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance. */ src: string | LazyCanvas; /** * Constructs a new Pattern instance. * @param opts {Object} - Optional properties for the pattern. * @param opts.props {IPattern} - The pattern properties. */ constructor(opts?: { props?: IPattern; }); /** * Sets the type of the pattern. * @param type {AnyPatternType} - The type of the pattern (e.g., repeat, no-repeat). * @returns {this} The current instance for chaining. */ setType(type: AnyPatternType): this; /** * Sets the source of the pattern. * @param src {string | LazyCanvas} - The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance. * @returns {this} The current instance for chaining. */ setSrc(src: string | LazyCanvas): this; /** * Draws the pattern on a canvas context. * @param ctx {SKRSContext2D} - The canvas rendering context. * @returns {Promise<CanvasPattern>} The created pattern. */ draw(ctx: SKRSContext2D): Promise<CanvasPattern>; /** * Converts the Pattern instance to a JSON representation. * @returns {IPattern} The JSON representation of the pattern. */ toJSON(): IPattern; }