1 | export const getSize = (value) => {
|
2 | return typeof value === 'number' ? `${value}px` : value;
|
3 | };
|
4 |
|
5 | export const getOffset = (elem) => {
|
6 | const doc = document.documentElement;
|
7 | const body = document.body;
|
8 | const rect = elem.getBoundingClientRect();
|
9 | const offset = {
|
10 | y: rect.top + (window.pageYOffset || doc.scrollTop) - (doc.clientTop || body.clientTop || 0),
|
11 | x: rect.left + (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || body.clientLeft || 0),
|
12 | };
|
13 | return offset;
|
14 | };
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export const getPos = (e, elem, isReverse, zoom = 1) => {
|
22 | const event = 'targetTouches' in e ? e.targetTouches[0] : e;
|
23 | const offset = getOffset(elem);
|
24 | const posObj = {
|
25 | x: event.pageX - offset.x,
|
26 | y: event.pageY - offset.y,
|
27 | };
|
28 | return {
|
29 | x: isReverse ? elem.offsetWidth * zoom - posObj.x : posObj.x,
|
30 | y: isReverse ? elem.offsetHeight * zoom - posObj.y : posObj.y,
|
31 | };
|
32 | };
|
33 | export const getKeyboardHandleFunc = (e, params) => {
|
34 | if (params.hook) {
|
35 | const result = params.hook(e);
|
36 | if (typeof result === 'function')
|
37 | return result;
|
38 | if (!result)
|
39 | return null;
|
40 | }
|
41 | switch (e.keyCode) {
|
42 | case 38 :
|
43 | return i => (params.direction === 'ttb' ? i - 1 : i + 1);
|
44 | case 39 :
|
45 | return i => (params.direction === 'rtl' ? i - 1 : i + 1);
|
46 | case 40 :
|
47 | return i => (params.direction === 'ttb' ? i + 1 : i - 1);
|
48 | case 37 :
|
49 | return i => (params.direction === 'rtl' ? i + 1 : i - 1);
|
50 | case 35 :
|
51 | return () => params.max;
|
52 | case 36 :
|
53 | return () => params.min;
|
54 | case 33 :
|
55 | return i => i + 10;
|
56 | case 34 :
|
57 | return i => i - 10;
|
58 | default:
|
59 | return null;
|
60 | }
|
61 | };
|
62 |
|
\ | No newline at end of file |