You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
1.8 KiB
TypeScript
100 lines
1.8 KiB
TypeScript
2 years ago
|
import {
|
||
|
ArrowIcon,
|
||
|
DiamondIcon,
|
||
|
EllipseIcon,
|
||
|
EraserIcon,
|
||
|
FreedrawIcon,
|
||
|
ImageIcon,
|
||
|
LineIcon,
|
||
|
RectangleIcon,
|
||
|
SelectionIcon,
|
||
|
TextIcon,
|
||
|
} from "./components/icons";
|
||
4 years ago
|
import { KEYS } from "./keys";
|
||
5 years ago
|
|
||
5 years ago
|
export const SHAPES = [
|
||
|
{
|
||
2 years ago
|
icon: SelectionIcon,
|
||
5 years ago
|
value: "selection",
|
||
4 years ago
|
key: KEYS.V,
|
||
2 years ago
|
numericKey: KEYS["1"],
|
||
2 years ago
|
fillable: true,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: RectangleIcon,
|
||
5 years ago
|
value: "rectangle",
|
||
4 years ago
|
key: KEYS.R,
|
||
2 years ago
|
numericKey: KEYS["2"],
|
||
2 years ago
|
fillable: true,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: DiamondIcon,
|
||
5 years ago
|
value: "diamond",
|
||
4 years ago
|
key: KEYS.D,
|
||
2 years ago
|
numericKey: KEYS["3"],
|
||
2 years ago
|
fillable: true,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: EllipseIcon,
|
||
5 years ago
|
value: "ellipse",
|
||
3 years ago
|
key: KEYS.O,
|
||
2 years ago
|
numericKey: KEYS["4"],
|
||
2 years ago
|
fillable: true,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: ArrowIcon,
|
||
5 years ago
|
value: "arrow",
|
||
4 years ago
|
key: KEYS.A,
|
||
2 years ago
|
numericKey: KEYS["5"],
|
||
2 years ago
|
fillable: true,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: LineIcon,
|
||
5 years ago
|
value: "line",
|
||
2 years ago
|
key: KEYS.L,
|
||
|
numericKey: KEYS["6"],
|
||
2 years ago
|
fillable: true,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: FreedrawIcon,
|
||
4 years ago
|
value: "freedraw",
|
||
2 years ago
|
key: [KEYS.P, KEYS.X],
|
||
2 years ago
|
numericKey: KEYS["7"],
|
||
2 years ago
|
fillable: false,
|
||
5 years ago
|
},
|
||
|
{
|
||
2 years ago
|
icon: TextIcon,
|
||
5 years ago
|
value: "text",
|
||
4 years ago
|
key: KEYS.T,
|
||
2 years ago
|
numericKey: KEYS["8"],
|
||
2 years ago
|
fillable: false,
|
||
5 years ago
|
},
|
||
3 years ago
|
{
|
||
2 years ago
|
icon: ImageIcon,
|
||
3 years ago
|
value: "image",
|
||
|
key: null,
|
||
2 years ago
|
numericKey: KEYS["9"],
|
||
2 years ago
|
fillable: false,
|
||
|
},
|
||
|
{
|
||
|
icon: EraserIcon,
|
||
|
value: "eraser",
|
||
|
key: KEYS.E,
|
||
2 years ago
|
numericKey: KEYS["0"],
|
||
2 years ago
|
fillable: false,
|
||
3 years ago
|
},
|
||
5 years ago
|
] as const;
|
||
5 years ago
|
|
||
5 years ago
|
export const findShapeByKey = (key: string) => {
|
||
|
const shape = SHAPES.find((shape, index) => {
|
||
|
return (
|
||
2 years ago
|
(shape.numericKey != null && key === shape.numericKey.toString()) ||
|
||
3 years ago
|
(shape.key &&
|
||
|
(typeof shape.key === "string"
|
||
|
? shape.key === key
|
||
|
: (shape.key as readonly string[]).includes(key)))
|
||
5 years ago
|
);
|
||
|
});
|
||
|
return shape?.value || null;
|
||
|
};
|