mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

* 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>
34 lines
967 B
TypeScript
34 lines
967 B
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import { fabric } from "fabric";
|
|
import type { Shape } from "image-occlusion/shapes";
|
|
|
|
import { addBorder, disableRotation, enableUniformScaling } from "./lib";
|
|
|
|
export const addShape = (
|
|
canvas: fabric.Canvas,
|
|
shape: Shape,
|
|
): void => {
|
|
const fabricShape = shape.toFabric(canvas);
|
|
addBorder(fabricShape);
|
|
disableRotation(fabricShape);
|
|
if (fabricShape.type === "i-text") {
|
|
enableUniformScaling(canvas, fabricShape);
|
|
}
|
|
canvas.add(fabricShape);
|
|
};
|
|
|
|
export const addShapeGroup = (
|
|
canvas: fabric.Canvas,
|
|
shapes: Shape[],
|
|
): void => {
|
|
const group = new fabric.Group();
|
|
shapes.map((shape) => {
|
|
const fabricShape = shape.toFabric(canvas);
|
|
addBorder(fabricShape);
|
|
group.addWithUpdate(fabricShape);
|
|
disableRotation(group);
|
|
});
|
|
canvas.add(group);
|
|
};
|