mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: add support for regular polygon shape with customizable sides
This commit is contained in:
parent
2a0d15799c
commit
c8d38e87b0
24 changed files with 329 additions and 67 deletions
|
@ -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,
|
||||
};
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue