import { BrushBasicConfig, BrushConfig } from "./types/config"; import { Module } from "./types/modules"; import { PointCallBack } from "./types/point"; /** * Basic brush object * * @param canvas Canvas Element (If not, please use loadContext to load it later) * @param config Brush Config (If not, please access the config property later or use the loadConfig function to modify it) */ export declare class Brush { /*********************************** Canvas State ***********************************/ private canvas?; private context?; private oriCanvas?; private oriContext?; private strokeCanvas?; private strokeContext?; private transferCanvas?; private transferContext?; private shapeCanvas?; private shapeContext?; private previousRotationAngle; private lastProcessedPointForRotation?; private _pendingFirstPointIndex?; private strokeHistory; private _strokeOpacity; isEraser: boolean; isAlphaLocked: boolean; private points; private drawCount; private prePoint?; private prePrePoint?; private isRender; private modules; private readonly minSpacePixel; private readonly maxPointsPerFrame; private readonly lagDistance; private get shapeRatio(); /** Brush Config */ config: BrushBasicConfig; /** Is curve smoothing enabled (default: true) */ isSmooth: boolean; /** Is interpolation filling enabled (default: true) */ isSpacing: boolean; /** Blend Mode (default: 'source-over') */ blendMode: CanvasRenderingContext2D["globalCompositeOperation"]; /** Filter (default: 'none') */ filter: CanvasRenderingContext2D["filter"]; /** Called after a render frame writes pixels to the target canvas. */ onRender?: () => void; constructor(canvas?: HTMLCanvasElement, config?: BrushConfig); /*********************************** Public API ***********************************/ /** * Load the canvas you want to draw * @param canvas */ loadContext(canvas: HTMLCanvasElement): void; /** * Syncs oriCanvas with current source canvas state. * Call this whenever the underlying source canvas pixels have been modified directly. */ syncOriCanvas(): void; /** * Load/Modify Brush Configuration * * This function only exists in the config field. * * You can also modify brush.config * * @example * brush.loadConfig({size: 10}) * brush.config.size = 10 */ loadConfig(config: BrushConfig): void; /** * Bind config to brush. * * If you do this, the brush config will change with the external config */ bindConfig(config: BrushBasicConfig): void; /** * This function allows loading images as brush styles. * * The image format has strict requirements. * Please use '.png' images with a transparent background or other image formats * with a transparent background. Pixels with content in the image will be used as the pattern shape. * * Tip: It takes some time to load images based on URL (string) ! ! ! * Pls use 'callback' param or 'loadImageAsync' Function If img as string ! ! ! */ loadImage(img: HTMLImageElement | HTMLCanvasElement | string, callback?: (isSuc: boolean) => void): void; /** * Asynchronous version of 'loadImage' */ loadImageAsync(img: HTMLImageElement | HTMLCanvasElement | string): Promise; removeImage(): void; /** * Add the current point to the point pool, * which will be rendered when the render function is called * (interpolation and Bessel calculations will be performed) */ putPoint(x: number, y: number, pressure: number): void; private processInitialSegment; /** * Start rendering the coordinate queue data until all the queue data has been rendered, * which means that once the render function is run, * it will only end when all the coordinate queues have been rendered * * The render will not run the second one repeatedly. * If the rendering is not completed and the render is called repeatedly, * it will not produce any effect, so feel free to call it */ render(): void; /** * Reset brush run data * * This reset does not clear the queue data that has not been fully rendered yet. * It only eliminates the impact of the current pen on the next one. * If not cleared, there may be a connection between the end of the previous pen * and the beginning of the current pen, as well as other bugs */ finalizeStroke(callback?: PointCallBack): void; /** * Clear all canvas */ clear(): void; /** * Use a module * @returns module unique id */ useModule(module: Module): string; /** * Remove a module */ removeModule(uniqueId: string): boolean; /*********************************** Internal Helpers ***********************************/ private assertCanvasReady; private initSourceCanvas; private initOriCanvas; private initStrokeCanvas; private initTransferCanvasCanvas; private resetStrokeState; private imageInitColoring; private loadImageWithCanvas; private loadImageWithElement; private loadImageWithUrl; private processPoint; private cloneConfig; private clamp01; private newPoint; private getMixedCanvas; private getCompositeOperation; private mixin; private endStroke; private draw; resize(width: number, height: number): void; } //# sourceMappingURL=Brush.d.ts.map