excalidraw/src/element/newElement.ts
2020-01-08 19:54:42 +01:00

42 lines
732 B
TypeScript

import { randomSeed } from "../random";
import nanoid from "nanoid";
export function newElement(
type: string,
x: number,
y: number,
strokeColor: string,
backgroundColor: string,
fillStyle: string,
strokeWidth: number,
roughness: number,
opacity: number,
width = 0,
height = 0
) {
const element = {
id: nanoid(),
type,
x,
y,
width,
height,
strokeColor,
backgroundColor,
fillStyle,
strokeWidth,
roughness,
opacity,
isSelected: false,
seed: randomSeed()
};
return element;
}
export function duplicateElement(element: ReturnType<typeof newElement>) {
const copy = { ...element };
copy.id = nanoid();
copy.seed = randomSeed();
return copy;
}