-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
546 lines (472 loc) · 25.2 KB
/
index.html
File metadata and controls
546 lines (472 loc) · 25.2 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folder Structure Visualizer</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.dropzone {
border: 2px dashed #ccc;
transition: all 0.3s ease;
}
.dropzone.active {
border-color: #4F46E5;
background-color: rgba(79, 70, 229, 0.05);
}
.folder-item {
transition: background-color 0.2s ease;
}
.folder-item:hover {
background-color: #f3f4f6;
}
.copy-btn {
opacity: 0;
transition: opacity 0.2s ease;
}
.folder-item:hover .copy-btn {
opacity: 1;
}
#structureText {
max-height: 300px;
overflow-y: auto;
font-family: monospace;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-6xl">
<div class="text-center mb-8">
<h1 class="text-3xl font-bold text-gray-800 mb-2">Folder Structure Visualizer</h1>
<p class="text-gray-600 max-w-lg mx-auto">Upload or drop a folder to visualize its structure. Easily copy the folder hierarchy for documentation.</p>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Upload Section -->
<div class="bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Upload Folder</h2>
<div id="dropzone" class="dropzone rounded-lg p-8 text-center cursor-pointer mb-4">
<div class="flex flex-col items-center justify-center">
<div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mb-3">
<i class="fas fa-folder-open text-indigo-500 text-2xl"></i>
</div>
<p class="text-gray-700 mb-1">Drag & drop your folder here</p>
<p class="text-gray-500 text-sm">or</p>
<input type="file" id="folderInput" webkitdirectory directory multiple class="hidden">
<button id="browseBtn" class="mt-2 px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition-colors">
Browse Files
</button>
</div>
</div>
<div class="text-sm text-gray-500">
<p><i class="fas fa-info-circle mr-1"></i> Only unzipped folders are supported. The app will not upload your files - it only analyzes the structure.</p>
</div>
</div>
<!-- Results Section -->
<div id="resultsSection" class="bg-white rounded-xl shadow-md p-6 hidden">
<div class="flex justify-between items-start mb-4">
<h2 class="text-xl font-semibold text-gray-800">Folder Structure</h2>
<div class="flex space-x-2">
<button id="copyStructureBtn" class="px-3 py-1.5 text-sm bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition-colors flex items-center">
<i class="fas fa-copy mr-1"></i> Copy
</button>
<button id="resetBtn" class="px-3 py-1.5 text-sm bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition-colors flex items-center">
<i class="fas fa-redo mr-1"></i> Reset
</button>
</div>
</div>
<div class="flex space-x-4 mb-4">
<div class="flex-1">
<div class="text-sm font-medium text-gray-500 mb-1">Visual Tree</div>
<div id="folderTree" class="bg-gray-50 rounded-lg border border-gray-200 p-4 overflow-y-auto max-h-80">
<!-- Tree view will be inserted here -->
</div>
</div>
<div class="flex-1">
<div class="text-sm font-medium text-gray-500 mb-1">Text Representation</div>
<div id="structureText" class="bg-gray-50 rounded-lg border border-gray-200 p-4 whitespace-pre"></div>
</div>
</div>
<div class="text-sm text-gray-500 flex items-start">
<i class="fas fa-info-circle mr-1 mt-0.5"></i>
<div>
<p>Click on folder icons to expand/collapse. Click the copy button to copy the folder structure to clipboard.</p>
<p class="mt-1">Files: <span id="fileCount" class="font-medium">0</span> | Folders: <span id="folderCount" class="font-medium">0</span></p>
</div>
</div>
</div>
<!-- Empty State -->
<div id="emptyState" class="hidden lg:flex col-span-2 bg-white rounded-xl shadow-md p-6 items-center justify-center">
<div class="text-center max-w-md">
<img src="https://storage.googleapis.com/workspace-0f70711f-8b4e-4d94-86f1-2a93ccde5887/image/071a248d-8d97-419a-9dc8-8c7966e7e029.png" alt="Illustration of a folder with branches representing structure - light blue background with simple line art style" class="mx-auto mb-4 rounded-lg">
<h3 class="text-xl font-medium text-gray-800 mb-2">No Folder Processed</h3>
<p class="text-gray-600">Upload a folder to visualize its structure. The app will display a navigable tree view and text representation you can copy.</p>
</div>
</div>
</div>
<div class="mt-8 text-center text-sm text-gray-500">
<p>Folder Structure Visualizer © 2023 | All processing happens locally in your browser</p>
</div>
</div>
<!-- Toast Notification -->
<div id="toast" class="fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-md shadow-lg transform translate-y-10 opacity-0 transition-all duration-300 flex items-center">
<i class="fas fa-check-circle mr-2"></i>
<span>Copied to clipboard!</span>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropzone = document.getElementById('dropzone');
const folderInput = document.getElementById('folderInput');
const browseBtn = document.getElementById('browseBtn');
const resultsSection = document.getElementById('resultsSection');
const emptyState = document.getElementById('emptyState');
const folderTree = document.getElementById('folderTree');
const structureText = document.getElementById('structureText');
const copyStructureBtn = document.getElementById('copyStructureBtn');
const resetBtn = document.getElementById('resetBtn');
const toast = document.getElementById('toast');
const fileCount = document.getElementById('fileCount');
const folderCount = document.getElementById('folderCount');
let currentStructure = null;
let stats = { files: 0, folders: 0 };
// Set up dropzone
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropzone.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropzone.classList.add('active');
}
function unhighlight() {
dropzone.classList.remove('active');
}
// Handle file drop
dropzone.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = [...dt.items]
.filter(item => item.kind === 'file')
.map(item => item.webkitGetAsEntry());
if (files.length > 0) {
const entry = files[0];
if (entry.isDirectory) {
processDirectory(entry);
} else {
showError('Please drop a folder, not files.');
}
}
}
// Handle file input via button
browseBtn.addEventListener('click', () => {
folderInput.click();
});
folderInput.addEventListener('change', (e) => {
const files = [...e.target.files];
if (files.length > 0) {
// Chrome creates a fake directory entry for the input
const path = files[0].webkitRelativePath;
const dirname = path.split('/')[0];
const fakeEntry = {
isDirectory: true,
name: dirname,
createReader: function() {
const dirFiles = files.filter(f => f.webkitRelativePath.startsWith(dirname + '/'));
return {
readEntries: function(callback) {
// Group files by directory structure
const dirMap = new Map();
dirFiles.forEach(file => {
const parts = file.webkitRelativePath.split('/').slice(1);
let currentLevel = parts.slice(0, -1);
const fileName = parts[parts.length - 1];
let currentMap = dirMap;
currentLevel.forEach(dir => {
if (!currentMap.has(dir)) {
currentMap.set(dir, new Map());
}
currentMap = currentMap.get(dir);
});
if (!currentMap.has('_files')) {
currentMap.set('_files', []);
}
currentMap.get('_files').push(fileName);
});
// Convert the nested Map structure to entries
function mapToEntries(map, currentPath = '') {
const entries = [];
map.forEach((value, key) => {
if (key === '_files') {
value.forEach(filename => {
entries.push({
isDirectory: false,
isFile: true,
name: filename,
fullPath: currentPath + filename
});
});
} else {
const dirEntry = {
isDirectory: true,
name: key,
fullPath: currentPath + key,
createReader: function() {
return {
readEntries: function(callback) {
callback(mapToEntries(value, currentPath + key + '/'));
}
};
}
};
entries.push(dirEntry);
}
});
return entries;
}
callback(mapToEntries(dirMap));
}
};
}
};
processDirectory(fakeEntry);
}
});
// Process the directory structure
function processDirectory(directory) {
stats = { files: 0, folders: 0 };
readDirectory(directory, '', (err, structure) => {
if (err) {
showError('Error reading folder structure: ' + err.message);
return;
}
currentStructure = structure;
renderTree(structure);
renderTextStructure(structure);
updateStats();
emptyState.classList.add('hidden');
resultsSection.classList.remove('hidden');
});
}
function readDirectory(directory, path, callback) {
const reader = directory.createReader();
const result = {
name: directory.name,
path: path + directory.name,
children: [],
type: 'directory'
};
stats.folders++;
reader.readEntries(function(entries) {
const promises = [];
entries.forEach(entry => {
const promise = new Promise(resolve => {
if (entry.isDirectory) {
readDirectory(entry, result.path + '/', (err, child) => {
if (!err) {
result.children.push(child);
}
resolve();
});
} else {
stats.files++;
result.children.push({
name: entry.name,
path: result.path + '/' + entry.name,
type: 'file'
});
resolve();
}
});
promises.push(promise);
});
Promise.all(promises).then(() => {
// Sort directories first, then files, both alphabetically
result.children.sort((a, b) => {
if (a.type === 'directory' && b.type !== 'directory') return -1;
if (a.type !== 'directory' && b.type === 'directory') return 1;
return a.name.localeCompare(b.name);
});
callback(null, result);
});
}, function(error) {
callback(error);
});
}
// Render the folder tree
function renderTree(structure) {
folderTree.innerHTML = '';
const ul = document.createElement('ul');
ul.className = 'space-y-1';
buildTreeItem(structure, ul, true);
folderTree.appendChild(ul);
}
function buildTreeItem(item, parentElement, isRoot = false) {
const li = document.createElement('li');
li.className = 'folder-item';
const div = document.createElement('div');
div.className = 'flex items-center py-1 px-2 rounded-md';
if (item.type === 'directory') {
// Folder item
const toggle = document.createElement('span');
toggle.className = 'mr-1 text-gray-500 cursor-pointer w-4 flex-none';
toggle.innerHTML = '<i class="fas fa-chevron-right text-xs"></i>';
const icon = document.createElement('span');
icon.className = 'mr-2 text-yellow-500';
icon.innerHTML = '<i class="fas fa-folder"></i>';
const name = document.createElement('span');
name.className = 'flex-1 truncate';
name.textContent = item.name;
const copyBtn = document.createElement('span');
copyBtn.className = 'copy-btn ml-2 text-gray-400 hover:text-gray-600 cursor-pointer';
copyBtn.innerHTML = '<i class="fas fa-copy text-xs"></i>';
copyBtn.title = 'Copy path';
copyBtn.addEventListener('click', (e) => {
e.stopPropagation();
copyToClipboard(item.path);
});
div.appendChild(toggle);
div.appendChild(icon);
div.appendChild(name);
div.appendChild(copyBtn);
// Children container
const childrenContainer = document.createElement('div');
childrenContainer.className = 'pl-4 border-l-2 border-gray-200 hidden';
if (item.children.length > 0) {
const ul = document.createElement('ul');
ul.className = 'space-y-1';
item.children.forEach(child => {
buildTreeItem(child, ul);
});
childrenContainer.appendChild(ul);
}
// Toggle children on click
div.addEventListener('click', () => {
const isExpanded = toggle.innerHTML.includes('chevron-down');
if (isExpanded) {
toggle.innerHTML = '<i class="fas fa-chevron-right text-xs"></i>';
childrenContainer.classList.add('hidden');
} else {
toggle.innerHTML = '<i class="fas fa-chevron-down text-xs"></i>';
childrenContainer.classList.remove('hidden');
}
});
li.appendChild(div);
li.appendChild(childrenContainer);
} else {
// File item
const icon = document.createElement('span');
icon.className = 'mr-2 text-gray-500 ml-4';
icon.innerHTML = '<i class="fas fa-file"></i>';
const name = document.createElement('span');
name.className = 'flex-1 truncate';
name.textContent = item.name;
const copyBtn = document.createElement('span');
copyBtn.className = 'copy-btn ml-2 text-gray-400 hover:text-gray-600 cursor-pointer';
copyBtn.innerHTML = '<i class="fas fa-copy text-xs"></i>';
copyBtn.title = 'Copy path';
copyBtn.addEventListener('click', (e) => {
e.stopPropagation();
copyToClipboard(item.path);
});
div.appendChild(icon);
div.appendChild(name);
div.appendChild(copyBtn);
li.appendChild(div);
}
parentElement.appendChild(li);
}
// Render the text structure
function renderTextStructure(structure, level = 0) {
let text = '';
const indent = ' '.repeat(level);
const connector = level > 0 ? '│ '.repeat(level - 1) + '├── ' : '';
if (level === 0) {
text += structure.name + '\n';
}
structure.children.forEach((child, index) => {
const isLast = index === structure.children.length - 1;
const branch = isLast ? '└── ' : '├── ';
if (child.type === 'directory') {
text += connector + branch + child.name + '\n';
text += renderTextStructure(child, level + 1);
} else {
text += connector + branch + child.name + '\n';
}
});
if (level === 0) {
structureText.textContent = text;
}
return text;
}
// Update file/folder stats
function updateStats() {
fileCount.textContent = stats.files;
folderCount.textContent = stats.folders;
}
// Copy to clipboard
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
showToast('Copied to clipboard!');
}).catch(err => {
showError('Failed to copy: ' + err);
});
}
// Copy the entire structure
copyStructureBtn.addEventListener('click', () => {
if (currentStructure) {
copyToClipboard(structureText.textContent);
}
});
// Reset the app
resetBtn.addEventListener('click', () => {
currentStructure = null;
stats = { files: 0, folders: 0 };
folderTree.innerHTML = '';
structureText.textContent = '';
fileCount.textContent = '0';
folderCount.textContent = '0';
folderInput.value = '';
resultsSection.classList.add('hidden');
emptyState.classList.remove('hidden');
});
// Show toast notification
function showToast(message) {
toast.querySelector('span').textContent = message;
toast.classList.remove('translate-y-10', 'opacity-0');
toast.classList.add('translate-y-0', 'opacity-100');
setTimeout(() => {
toast.classList.remove('translate-y-0', 'opacity-100');
toast.classList.add('translate-y-10', 'opacity-0');
}, 3000);
}
// Show error message
function showError(message) {
const errorToast = toast.cloneNode(true);
errorToast.className = errorToast.className.replace('bg-green-500', 'bg-red-500');
errorToast.querySelector('i').className = 'fas fa-exclamation-triangle mr-2';
errorToast.querySelector('span').textContent = message;
document.body.appendChild(errorToast);
setTimeout(() => {
errorToast.classList.remove('translate-y-10', 'opacity-0');
errorToast.classList.add('translate-y-0', 'opacity-100');
setTimeout(() => {
errorToast.classList.remove('translate-y-0', 'opacity-100');
errorToast.classList.add('translate-y-10', 'opacity-0');
setTimeout(() => {
document.body.removeChild(errorToast);
}, 300);
}, 3000);
}, 10);
}
});
</script>
</body>
</html>