-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
77 lines (66 loc) · 2.08 KB
/
utils.js
File metadata and controls
77 lines (66 loc) · 2.08 KB
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
68
69
70
71
72
73
74
75
76
async function swapCells(cell1, cell2) {
const rect1 = cell1.getBoundingClientRect();
const rect2 = cell2.getBoundingClientRect();
const deltaX = rect2.left - rect1.left;
const deltaY = rect2.top - rect1.top;
// Set initial positions
cell1.style.transition = "none";
cell2.style.transition = "none";
cell1.style.transform = "none";
cell2.style.transform = "none";
// Trigger reflow
cell1.offsetHeight;
cell2.offsetHeight;
// Add transition and move
cell1.style.transition = "transform 0.3s ease-in-out";
cell2.style.transition = "transform 0.3s ease-in-out";
cell1.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
cell2.style.transform = `translate(${-deltaX}px, ${-deltaY}px)`;
// After animation, swap DOM positions
await new Promise((resolve) => {
setTimeout(() => {
cell1.style.transition = "none";
cell2.style.transition = "none";
cell1.style.transform = "none";
cell2.style.transform = "none";
const temp = cell1.nextSibling;
cell2.parentNode.insertBefore(cell1, cell2.nextSibling);
cell1.parentNode.insertBefore(cell2, temp);
resolve();
}, 300);
});
}
function findValueIndices(array2D, searchValue) {
for (let i = 0; i < array2D.length; i++) {
for (let j = 0; j < array2D[i].length; j++) {
if (array2D[i][j] == searchValue) {
return [i, j];
}
}
}
return null;
}
function findChildByContent(parentElement, searchContent) {
const children = parentElement.children;
for (let child of children) {
if (child.textContent == searchContent) {
return child;
}
}
return null;
}
function findElementByContent(nodeList, searchValue) {
for (let node of nodeList) {
if (node.textContent == searchValue) {
return node;
}
}
return null;
}
function updateGapSlider(gapInput) {
const value = gapInput.value;
const min = gapInput.min || 0;
const max = gapInput.max || 100;
const percentage = ((value - min) / (max - min)) * 100;
gapInput.style.background = `linear-gradient(to right, rebeccapurple ${percentage}%, #ddd ${percentage}%)`;
}