Files
excalidraw/src/element/newElement.ts
T
Gasim Gasimzada 74764b06eb Regenerate roughjs shape only when the item is updated (#316)
* Regenerate roughjs shape only when the item is updated

* Remove shape object during export and history undo/redo

* Remove shape element during copying

* Fix shape generation during creation
2020-01-11 16:00:00 -08:00

44 lines
826 B
TypeScript

import { randomSeed } from "../random";
import nanoid from "nanoid";
import { Drawable } from "roughjs/bin/core";
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(),
shape: null as Drawable | Drawable[] | null
};
return element;
}
export function duplicateElement(element: ReturnType<typeof newElement>) {
const copy = { ...element };
copy.id = nanoid();
copy.seed = randomSeed();
return copy;
}