-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
116 lines (97 loc) · 2.69 KB
/
index.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Images</title>
<script src="./utils.js"></script>
<script src="./config.js"></script>
<script src="./canvas.js"></script>
<script src="./file.js"></script>
<script src="./image.js"></script>
<script src="./worker.js"></script>
<script src="./main.js"></script>
<script>
Object.defineProperty(Array.prototype, 'chunk', {
value: function (chunkSize) {
var R = [];
for (var i = 0; i < this.length; i += chunkSize)
R.push(this.slice(i, i + chunkSize));
return R;
}
});
</script>
<style>
.hint {
display: none;
}
.hint:nth-child(2) {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
box-sizing: border-box;
width: calc(100% - 6rem);
height: calc(100% - 6rem);
padding: 1rem;
margin: 3rem;
border-radius: 3rem;
border: 2rem dashed currentColor;
color: rgb(190, 190, 190);
font-size: 2rem;
word-wrap: break-word;
}
body {
overflow: scroll;
margin: 0;
}
.image-row {
display: flex;
height: auto;
}
.image-row img,
.image-row canvas {
display: none;
}
.image-row.show img,
.image-row.show canvas {
display: block;
}
</style>
</head>
<body>
<div id="tag"></div>
<div class="hint"> Drop files / folders here! </div>
<script>
window.addEventListener("dragover", (event) => event.preventDefault());
window.addEventListener("drop", handleDrop);
async function handleDrop(event) {
document.querySelectorAll(".image-row").forEach(ele => ele.remove())
document.querySelectorAll("canvas").forEach(ele => ele.remove())
event.stopPropagation();
event.preventDefault();
var fileEntries = [...event.dataTransfer.items]
.filter(item => item.kind === "file")
.map(item => item.webkitGetAsEntry())
console.time("file")
const files = await traverseFileTree(fileEntries)
console.timeEnd("file")
const chunks = files.chunk(100)
console.time("total")
for (var chunk of chunks) {
console.time("chunk")
const a = await Promise.all(chunk.map(fileEntery => new Promise(resolve => {
fileEntery.file(resolve)
})));
console.timeEnd("chunk")
console.time("draw")
await main(a.map(file => ({ file })));
console.timeEnd("draw")
}
console.timeEnd("total")
return;
}
</script>
</body>
</html>