feat: add support for regular polygon shape with customizable sides

This commit is contained in:
Ayesha Imran 2025-04-28 12:45:54 +05:00
parent 2a0d15799c
commit c8d38e87b0
24 changed files with 329 additions and 67 deletions

View file

@ -46,6 +46,7 @@ import type {
ExcalidrawArrowElement,
FixedSegment,
ExcalidrawElbowArrowElement,
ExcalidrawRegularPolygonElement,
} from "./types";
export type ElementConstructorOpts = MarkOptional<
@ -471,6 +472,28 @@ export const newLinearElement = (
};
};
export const newRegularPolygonElement = (
opts: {
type: "regularPolygon";
sides?: number;
} & ElementConstructorOpts,
): NonDeleted<ExcalidrawRegularPolygonElement> => {
// create base element
const base = _newElementBase<ExcalidrawRegularPolygonElement>(
"regularPolygon",
opts,
);
// set default size if none provided
const width = opts.width ?? 100;
const height = opts.height ?? 100;
return {
...base,
sides: opts.sides ?? 6, // default to hexagon
width,
height,
};
};
export const newArrowElement = <T extends boolean>(
opts: {
type: ExcalidrawArrowElement["type"];
@ -532,4 +555,4 @@ export const newImageElement = (
scale: opts.scale ?? [1, 1],
crop: opts.crop ?? null,
};
};
};