react-fabric-canvas-designer
Version:
A React-based wrapper for Fabric.js to create interactive and customizable canvas-based designs. This library provides tools for drawing, editing, and managing objects on a canvas with React-friendly APIs.
26 lines (21 loc) • 888 B
text/typescript
import { Ellipse, FabricImage, FabricObject, Rect, Textbox, } from "fabric";
import { EllipseObj } from "./Objects/EllipseObj";
import { FabricImageObj } from "./Objects/FabricImageObj";
import { RectObj } from "./Objects/RectObj";
import { TextBoxObj } from "./Objects/TextBoxObj";
export class FabricObjectAdapter {
static createAdapter(type: string, fbObj: FabricObject) {
switch (type) {
case "rect":
return new RectObj(fbObj as Rect);
case "ellipse":
return new EllipseObj(fbObj as Ellipse);
case "image":
return new FabricImageObj(fbObj as FabricImage);
case "textbox":
return new TextBoxObj(fbObj as Textbox);
default:
throw new Error("Can not find the given object type " + type);
}
}
}