2020-01-06 19:34:22 +04:00
|
|
|
import { randomSeed } from "../random";
|
2020-01-07 23:49:39 +04:00
|
|
|
import nanoid from "nanoid";
|
2020-01-12 04:00:00 +04:00
|
|
|
import { Drawable } from "roughjs/bin/core";
|
2020-01-06 19:34:22 +04:00
|
|
|
|
|
|
|
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 = {
|
2020-01-07 23:49:39 +04:00
|
|
|
id: nanoid(),
|
2020-01-07 19:04:52 +04:00
|
|
|
type,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
strokeColor,
|
|
|
|
backgroundColor,
|
|
|
|
fillStyle,
|
|
|
|
strokeWidth,
|
|
|
|
roughness,
|
|
|
|
opacity,
|
2020-01-06 19:34:22 +04:00
|
|
|
isSelected: false,
|
2020-01-12 04:00:00 +04:00
|
|
|
seed: randomSeed(),
|
|
|
|
shape: null as Drawable | Drawable[] | null
|
2020-01-06 19:34:22 +04:00
|
|
|
};
|
|
|
|
return element;
|
|
|
|
}
|
2020-01-08 19:54:42 +01:00
|
|
|
|
|
|
|
export function duplicateElement(element: ReturnType<typeof newElement>) {
|
|
|
|
const copy = { ...element };
|
|
|
|
copy.id = nanoid();
|
|
|
|
copy.seed = randomSeed();
|
|
|
|
return copy;
|
|
|
|
}
|