excalidraw/src/element/newElement.ts
Preet 8dbd1b80df Update to rough.js 4.0.1 (#363)
* upgrade to latest rough.js

* remove random.ts because roughjs now supports seeding.
2020-01-13 11:04:28 -08:00

45 lines
854 B
TypeScript

import { randomSeed } from "roughjs/bin/math";
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 };
delete copy.shape;
copy.id = nanoid();
copy.seed = randomSeed();
return copy;
}