a53806e24a
* Simplify handling of occlusion types in editor code - Unify updateIONoteInEditMode(), setOcclusionFieldInner() and setOcclusionField() into updateOcclusionsField() - Don't use `includeInactive` property of Shape class in editor code - Drop `isEditMode` + Update the occlusions field every time a mask or text is updated, not only in editing mode but also in adding mode, so that IO cards can be previewed correctly in the card layout screen * Indicate current occlusion type in pop-up menu https://forums.ankiweb.net/t/anki-23-10-beta-5-6/35677/46 * Fix a11y warnings in Toolbar.svelte * Drop `occludeInactive` parameter from `MaskEditorAPI.getShapes()`
55 lines
1.4 KiB
TypeScript
55 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(shape: Shape): void {
|
|
addShape(this.canvas, shape);
|
|
}
|
|
|
|
addShapeGroup(shapes: Shape[]): void {
|
|
addShapeGroup(this.canvas, 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);
|
|
}
|
|
}
|