diff --git a/src/canvas/DotTextCanvas.ts b/src/canvas/DotTextCanvas.ts index 5a524e5..e76c791 100644 --- a/src/canvas/DotTextCanvas.ts +++ b/src/canvas/DotTextCanvas.ts @@ -15,6 +15,8 @@ export class DotTextCanvas { textPointSet: Array = [] status = 'pending' container?: HTMLElement + stop: () => void = () => {} + constructor( text: string, fontSize: number, @@ -100,7 +102,7 @@ export class DotTextCanvas { } }) } - useRic(tasks, { + this.stop = useRic(tasks, { callback: () => (this.status = 'success'), }) } @@ -112,6 +114,7 @@ export class DotTextCanvas { color: string, fontWeight: number, ): DotTextCanvas { + this.stop() const p = removeElement(this.canvas) if (!p) { throw new Error( @@ -136,6 +139,7 @@ export class DotTextCanvas { } clearCanvas() { + this.stop() this.ctx?.clearRect(0, 0, this.canvas!.width, this.canvas!.height) } @@ -143,4 +147,8 @@ export class DotTextCanvas { insertElement(container, this.canvas) return this } + destory() { + this.stop() + removeElement(this.canvas) + } }