import { Shape, ShapeType, ShapeByType, ShapeUtility } from 'types' import dot from './dot' import polyline from './polyline' import rectangle from './rectangle' import ellipse from './ellipse' import line from './line' import ray from './ray' import draw from './draw' import arrow from './arrow' import group from './group' import text from './text' // A mapping of shape types to shape utilities. const shapeUtilityMap: Record> = { [ShapeType.Rectangle]: rectangle, [ShapeType.Ellipse]: ellipse, [ShapeType.Draw]: draw, [ShapeType.Arrow]: arrow, [ShapeType.Text]: text, [ShapeType.Group]: group, [ShapeType.Dot]: dot, [ShapeType.Polyline]: polyline, [ShapeType.Line]: line, [ShapeType.Ray]: ray, } /** * A helper to retrieve a shape utility based on a shape object. * @param shape * @returns */ export function getShapeUtils(shape: T): ShapeUtility { return shapeUtilityMap[shape?.type] as ShapeUtility } export function createShape( type: T, props: Partial> ): ShapeByType { return shapeUtilityMap[type].create(props) as ShapeByType } export default shapeUtilityMap