forked from Kholid060/inspect-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
51 lines (38 loc) · 988 Bytes
/
helper.js
File metadata and controls
51 lines (38 loc) · 988 Bytes
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
/* eslint-disable */
export const generateGetBoundingClientRect = (x = 0, y = 0) => () => ({
width: 0,
height: 0,
top: y,
right: x,
bottom: y,
left: x,
});
export function copyToClipboard(text = '') {
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.top = 0;
textarea.style.left = 0;
textarea.style.opacity = 0;
textarea.style.position = 'fixed';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
document.execCommand('Copy');
textarea.remove();
return true;
}
export function debounce(func, wait, immediate) {
let timeout;
return function () {
const context = this;
const args = arguments;
const later = function () {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}