2020-03-09 15:06:35 +02:00
|
|
|
export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
|
2021-01-21 16:21:54 +01:00
|
|
|
export const isWindows = /^Win/.test(window.navigator.platform);
|
2020-03-09 15:06:35 +02:00
|
|
|
|
2020-12-01 23:36:06 +02:00
|
|
|
export const CODES = {
|
|
|
|
EQUAL: "Equal",
|
|
|
|
MINUS: "Minus",
|
|
|
|
NUM_ADD: "NumpadAdd",
|
|
|
|
NUM_SUBTRACT: "NumpadSubtract",
|
|
|
|
NUM_ZERO: "Numpad0",
|
|
|
|
BRACKET_RIGHT: "BracketRight",
|
|
|
|
BRACKET_LEFT: "BracketLeft",
|
|
|
|
ONE: "Digit1",
|
2020-12-13 14:54:35 -06:00
|
|
|
TWO: "Digit2",
|
2020-12-01 23:36:06 +02:00
|
|
|
NINE: "Digit9",
|
|
|
|
QUOTE: "Quote",
|
|
|
|
ZERO: "Digit0",
|
|
|
|
C: "KeyC",
|
|
|
|
G: "KeyG",
|
|
|
|
F: "KeyF",
|
|
|
|
H: "KeyH",
|
|
|
|
V: "KeyV",
|
2021-01-28 00:41:17 +05:30
|
|
|
X: "KeyX",
|
2020-12-01 23:36:06 +02:00
|
|
|
Z: "KeyZ",
|
2021-02-02 02:26:42 +05:30
|
|
|
R: "KeyR",
|
2020-12-01 23:36:06 +02:00
|
|
|
} as const;
|
|
|
|
|
2020-04-14 12:30:58 +03:00
|
|
|
export const KEYS = {
|
2020-12-01 23:36:06 +02:00
|
|
|
ARROW_DOWN: "ArrowDown",
|
2020-04-14 12:30:58 +03:00
|
|
|
ARROW_LEFT: "ArrowLeft",
|
|
|
|
ARROW_RIGHT: "ArrowRight",
|
|
|
|
ARROW_UP: "ArrowUp",
|
|
|
|
BACKSPACE: "Backspace",
|
2020-12-06 22:39:31 +00:00
|
|
|
ALT: "Alt",
|
2020-04-14 12:30:58 +03:00
|
|
|
CTRL_OR_CMD: isDarwin ? "metaKey" : "ctrlKey",
|
2020-12-01 23:36:06 +02:00
|
|
|
DELETE: "Delete",
|
|
|
|
ENTER: "Enter",
|
|
|
|
ESCAPE: "Escape",
|
2020-04-14 12:30:58 +03:00
|
|
|
QUESTION_MARK: "?",
|
2020-12-01 23:36:06 +02:00
|
|
|
SPACE: " ",
|
|
|
|
TAB: "Tab",
|
|
|
|
|
|
|
|
A: "a",
|
|
|
|
D: "d",
|
|
|
|
E: "e",
|
|
|
|
L: "l",
|
2021-01-06 13:36:55 +01:00
|
|
|
O: "o",
|
2020-12-01 23:36:06 +02:00
|
|
|
P: "p",
|
|
|
|
Q: "q",
|
|
|
|
R: "r",
|
|
|
|
S: "s",
|
|
|
|
T: "t",
|
|
|
|
V: "v",
|
|
|
|
X: "x",
|
2021-01-21 16:21:54 +01:00
|
|
|
Y: "y",
|
2020-12-01 23:36:06 +02:00
|
|
|
Z: "z",
|
2020-04-14 12:30:58 +03:00
|
|
|
} as const;
|
2020-01-09 02:00:59 +04:00
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
export type Key = keyof typeof KEYS;
|
|
|
|
|
2020-12-01 23:36:06 +02:00
|
|
|
export const isArrowKey = (key: string) =>
|
|
|
|
key === KEYS.ARROW_LEFT ||
|
|
|
|
key === KEYS.ARROW_RIGHT ||
|
|
|
|
key === KEYS.ARROW_DOWN ||
|
|
|
|
key === KEYS.ARROW_UP;
|
2020-04-22 16:57:17 +01:00
|
|
|
|
|
|
|
export const getResizeCenterPointKey = (event: MouseEvent | KeyboardEvent) =>
|
2020-12-01 23:36:06 +02:00
|
|
|
event.altKey;
|
2020-05-20 16:21:37 +03:00
|
|
|
|
2020-12-06 22:39:31 +00:00
|
|
|
export const getResizeWithSidesSameLengthKey = (
|
|
|
|
event: MouseEvent | KeyboardEvent,
|
|
|
|
) => event.shiftKey;
|
2020-06-24 00:24:52 +09:00
|
|
|
|
2020-12-06 22:39:31 +00:00
|
|
|
export const getRotateWithDiscreteAngleKey = (
|
|
|
|
event: MouseEvent | KeyboardEvent,
|
|
|
|
) => event.shiftKey;
|