-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.helper.js
63 lines (51 loc) · 1.48 KB
/
util.helper.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
// others
function preventRightClick(id) {
document.getElementById(id).addEventListener(
"contextmenu",
function (evt) {
evt.preventDefault();
},
false
);
}
// https://www.w3schools.com/howto/howto_js_copy_clipboard.asp
function copyToClipboard(id) {
/* Get the text field */
var copyText = document.getElementById(id);
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
/* Copy the text inside the text field */
document.execCommand("copy");
alert("Copied");
}
function getBound(rects) {
let top = Infinity,
left = Infinity,
right = -Infinity,
bottom = -Infinity;
for (let p of rects) {
top = min(p.y, top);
bottom = max(p.y + p.h, bottom);
left = min(p.x, left);
right = max(p.x + p.w, right);
}
return { top, left, right, bottom };
}
function calculateFitBound(w, h, bound, symmetry = false) {
const { top, left, right, bottom } = bound;
let W, H;
if (symmetry) {
W = abs(right) - abs(left) > 0 ? abs(right) * 2 : abs(left) * 2;
H = abs(bottom) - abs(top) > 0 ? abs(bottom) * 2 : abs(top) * 2;
} else {
W = abs(right) - abs(left) > 0 ? abs(right) : abs(left);
H = abs(bottom) - abs(top) > 0 ? abs(bottom) : abs(top);
}
let scaleRatio = min(w, h) / max(W, H);
return {
scaleRatio,
W: W,
H: H,
};
}