Anki/ts/image-occlusion/tools/api.ts
Mani ea8f0c1491
fix: blur in io, remove panzoom and use fabricjs for panzoom (#3052)
* fix: blur in io, remove panzoom and use fabricjs for panzoom
- remove panzoom
- implement panzoom using fabricjs
- set background image for canvas
- add bounding rect for canvas
- draw or add point inside in bounding rect
- update zoom tool

* support pinch to zoom on mobile client

* fix lagging of canvas, zoom in draw mode

* panning in touch events
2024-03-09 10:35:23 +00:00

54 lines
1.4 KiB
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { fabric } from "fabric";
import { baseShapesFromFabric, exportShapesToClozeDeletions } from "image-occlusion/shapes/to-cloze";
import type { ShapeOrShapes } from "../shapes";
import { Ellipse, Polygon, Rectangle, Shape, Text } from "../shapes";
import { addShape, addShapeGroup } from "./from-shapes";
import { clear, redraw } from "./lib";
interface ClozeExportResult {
clozes: string;
cardCount: number;
}
export class MaskEditorAPI {
readonly Shape = Shape;
readonly Rectangle = Rectangle;
readonly Ellipse = Ellipse;
readonly Polygon = Polygon;
readonly Text = Text;
readonly canvas: fabric.Canvas;
constructor(canvas) {
this.canvas = canvas;
}
addShape(bounding, shape: Shape): void {
addShape(this.canvas, bounding, shape);
}
addShapeGroup(bounding, shapes: Shape[]): void {
addShapeGroup(this.canvas, bounding, shapes);
}
getClozes(occludeInactive: boolean): ClozeExportResult {
const { clozes, noteCount: cardCount } = exportShapesToClozeDeletions(occludeInactive);
return { clozes, cardCount };
}
getShapes(): ShapeOrShapes[] {
return baseShapesFromFabric();
}
redraw(): void {
redraw(this.canvas);
}
clear(): void {
clear(this.canvas);
}
}