@tomiaa/canvas-graffiti
Version:
85 lines (84 loc) • 2.46 kB
TypeScript
import { ToolOptions } from "./types";
export * from "./types";
/**
* 配置
*/
export interface Options {
el: string | HTMLCanvasElement;
currentTool?: ToolType;
createBufferCanvasStyle?: {
[prop: string]: any;
};
allowType?: AllowType[];
allowButton?: (0 | 1 | 2)[];
}
export type EventTypes = "pointerdown" | "pointermove" | "pointerup";
export type ToolType = "Marker" | "Line" | "Rect" | "FillRect" | "Arc" | "FillRect" | "Erase";
export type AllowType = "mouse" | "touch" | "pen" | (string & {});
export declare class CanvasGraffiti implements ToolOptions {
options: Options;
el: HTMLCanvasElement;
beginPoint: {
x: number;
y: number;
};
endPoint: {
x: number;
y: number;
} | undefined;
points: {
x: number;
y: number;
}[];
currentTool: ToolType;
bufferCanvas: HTMLCanvasElement | undefined;
allowType: AllowType[];
allowButton: (0 | 1 | 2 | number)[];
get color(): string | CanvasGradient | CanvasPattern;
set color(value: string | CanvasGradient | CanvasPattern);
get lineWidth(): number;
set lineWidth(value: number);
get tool(): any;
set tool(value: any);
static toolList: readonly [{
readonly label: "记号笔";
readonly value: "Marker";
}, {
readonly label: "直线";
readonly value: "Line";
}, {
readonly label: "空心矩形";
readonly value: "Rect";
}, {
readonly label: "实心矩形";
readonly value: "FillRect";
}, {
readonly label: "空心圆";
readonly value: "Arc";
}, {
readonly label: "实心圆";
readonly value: "FillArc";
}];
static allowTypes: {
label: string;
value: string;
}[];
constructor(options: Options);
get ctx(): CanvasRenderingContext2D;
get bufferCtx(): CanvasRenderingContext2D | null | undefined;
/**
* 初始化
*/
init(): void;
bindCanvasEventListener(): void;
removeEventListener(types?: EventTypes[]): void;
pointerdown(event: PointerEvent): void;
pointermove(event: PointerEvent): void;
pointerup(event: PointerEvent): void;
clear(): void;
createBufferCanvas(): void;
destroy(isRemoveCanvas?: boolean): void;
toDataURL(type?: string, encoderOptions?: number): string;
toPicFile(filename?: string): Promise<File>;
}
export default CanvasGraffiti;