56f7d54900
* Add simple mask editor add-on API * Signal completed mask editor image loading to Python * Add API methods for querying mask editor state, fix formatting * Use event forwarding to propagate image loaded event Should fix mobile support by moving all bridgeCommand calls to `NoteEditor.svelte` * Add shape classes to mask editor API --------- Co-authored-by: Glutanimate <glutanimate@users.noreply.github.com>
24 lines
860 B
TypeScript
24 lines
860 B
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import type { GetImageOcclusionNoteResponse_ImageOcclusion } from "@tslib/anki/image_occlusion_pb";
|
|
import type { fabric } from "fabric";
|
|
import { extractShapesFromClozedField } from "image-occlusion/shapes/from-cloze";
|
|
|
|
import { addShape, addShapeGroup } from "./from-shapes";
|
|
import { redraw } from "./lib";
|
|
|
|
export const addShapesToCanvasFromCloze = (
|
|
canvas: fabric.Canvas,
|
|
occlusions: GetImageOcclusionNoteResponse_ImageOcclusion[],
|
|
): void => {
|
|
for (const shapeOrShapes of extractShapesFromClozedField(occlusions)) {
|
|
if (Array.isArray(shapeOrShapes)) {
|
|
addShapeGroup(canvas, shapeOrShapes);
|
|
} else {
|
|
addShape(canvas, shapeOrShapes);
|
|
}
|
|
}
|
|
redraw(canvas);
|
|
};
|