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);
|
2022-02-07 19:46:29 +01:00
|
|
|
export const isAndroid = /\b(android)\b/i.test(navigator.userAgent);
|
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",
|
2021-05-12 04:57:35 -04:00
|
|
|
SLASH: "Slash",
|
2020-12-01 23:36:06 +02:00
|
|
|
C: "KeyC",
|
2021-05-08 15:17:30 +05:30
|
|
|
D: "KeyD",
|
2020-12-01 23:36:06 +02:00
|
|
|
H: "KeyH",
|
|
|
|
V: "KeyV",
|
|
|
|
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",
|
2022-12-31 15:54:37 -06:00
|
|
|
PAGE_UP: "PageUp",
|
|
|
|
PAGE_DOWN: "PageDown",
|
2020-04-14 12:30:58 +03:00
|
|
|
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",
|
2022-01-12 15:21:36 +01:00
|
|
|
CHEVRON_LEFT: "<",
|
|
|
|
CHEVRON_RIGHT: ">",
|
|
|
|
PERIOD: ".",
|
|
|
|
COMMA: ",",
|
2020-12-01 23:36:06 +02:00
|
|
|
|
|
|
|
A: "a",
|
2022-10-20 21:01:26 +02:00
|
|
|
C: "c",
|
2020-12-01 23:36:06 +02:00
|
|
|
D: "d",
|
|
|
|
E: "e",
|
2022-10-20 21:01:26 +02:00
|
|
|
F: "f",
|
2021-05-28 17:22:42 +05:30
|
|
|
G: "g",
|
2022-10-20 21:01:26 +02:00
|
|
|
H: "h",
|
2021-10-21 22:05:48 +02:00
|
|
|
I: "i",
|
2020-12-01 23:36:06 +02:00
|
|
|
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",
|
2022-02-03 20:34:59 +05:30
|
|
|
K: "k",
|
2022-11-06 20:14:53 +01:00
|
|
|
|
|
|
|
0: "0",
|
|
|
|
1: "1",
|
|
|
|
2: "2",
|
|
|
|
3: "3",
|
|
|
|
4: "4",
|
|
|
|
5: "5",
|
|
|
|
6: "6",
|
|
|
|
7: "7",
|
|
|
|
8: "8",
|
|
|
|
9: "9",
|
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
|
|
|
|
2021-10-21 22:05:48 +02:00
|
|
|
export const shouldResizeFromCenter = (event: MouseEvent | KeyboardEvent) =>
|
2020-12-01 23:36:06 +02:00
|
|
|
event.altKey;
|
2020-05-20 16:21:37 +03:00
|
|
|
|
2021-10-21 22:05:48 +02:00
|
|
|
export const shouldMaintainAspectRatio = (event: MouseEvent | KeyboardEvent) =>
|
|
|
|
event.shiftKey;
|
2020-06-24 00:24:52 +09:00
|
|
|
|
2021-10-21 22:05:48 +02:00
|
|
|
export const shouldRotateWithDiscreteAngle = (
|
2022-08-01 21:41:50 +08:00
|
|
|
event: MouseEvent | KeyboardEvent | React.PointerEvent<HTMLCanvasElement>,
|
2020-12-06 22:39:31 +00:00
|
|
|
) => event.shiftKey;
|