-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathutils.js
67 lines (53 loc) · 1.05 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.range = range;
exports.clamp = clamp;
exports.getTouchPosition = getTouchPosition;
exports.getTouchId = getTouchId;
exports.omit = omit;
exports.modCursor = modCursor;
function range(start, end) {
var ret = [];
for (var i = start; i <= end; i++) {
ret.push(i);
}
return ret;
}
function clamp(n, min, max) {
if (n < min) {
return min;
}
if (n > max) {
return max;
}
return n;
}
function getTouchPosition(e) {
return {
x: e.changedTouches[0].pageX,
y: e.changedTouches[0].pageY
};
}
function getTouchId(e) {
return e.changedTouches[0].identifier;
}
function omit(obj, keys) {
var ret = {};
Object.keys(obj).forEach(function (k) {
if (keys.includes(k)) return;
ret[k] = obj[k];
});
return ret;
}
function modCursor(cursor, cardCount) {
var newCursor = cursor;
while (newCursor > 0) {
newCursor -= cardCount;
}
while (newCursor < 0.5 - cardCount) {
newCursor += cardCount;
}
return newCursor;
}