zhangxiao
2024-08-20 e47b788ff5f5c699c682999c95da17eb284ca21d
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
export function isFunction(func) {
    return typeof func === "function" || Object.prototype.toString.call(func) === "[object Function]";
}
 
export function snapToGrid(grid, pendingX, pendingY, scale = 1) {
    const x = Math.round(pendingX / scale / grid[0]) * grid[0];
    const y = Math.round(pendingY / scale / grid[1]) * grid[1];
 
    return [x, y];
}
 
export function getSize(el) {
    const rect = el.getBoundingClientRect();
 
    return [parseInt(rect.width), parseInt(rect.height)];
}
 
export function computeWidth(parentWidth, left, right) {
    return parentWidth - left - right;
}
 
export function computeHeight(parentHeight, top, bottom) {
    return parentHeight - top - bottom;
}
 
export function restrictToBounds(value, min, max) {
    if (min !== null && value < min) {
        return min;
    }
 
    if (max !== null && max < value) {
        return max;
    }
 
    return value;
}