Anki/ts/image-occlusion/tools/from-shapes.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

34 lines
954 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, enableUniformScaling } from "./lib";
export const addShape = (
canvas: fabric.Canvas,
boundingBox: fabric.Rect,
shape: Shape,
): void => {
const fabricShape = shape.toFabric(boundingBox);
addBorder(fabricShape);
if (fabricShape.type === "i-text") {
enableUniformScaling(canvas, fabricShape);
}
canvas.add(fabricShape);
};
export const addShapeGroup = (
canvas: fabric.Canvas,
boundingBox: fabric.Rect,
shapes: Shape[],
): void => {
const group = new fabric.Group();
shapes.map((shape) => {
const fabricShape = shape.toFabric(boundingBox);
addBorder(fabricShape);
group.addWithUpdate(fabricShape);
});
canvas.add(group);
};