Anki/ts/image-occlusion/tools/from-shapes.ts
Aristotelis 56f7d54900
Add APIs for IO mask editing (#2758)
* 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>
2023-10-22 10:40:40 +10:00

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);
};