pg0 commited on
Commit
47b70b4
·
verified ·
1 Parent(s): e54620f

Add 1 files

Browse files
Files changed (1) hide show
  1. index.html +39 -12
index.html CHANGED
@@ -102,7 +102,7 @@
102
  <div class="bg-gray-100 rounded-lg p-3 flex items-center">
103
  <i class="fas fa-file-image text-indigo-500 text-xl mr-3"></i>
104
  <div>
105
- <p id="fileName" class="text-sm font-medium text-gray-700 truncate max-w-xs"></p>
106
  <p id="fileSize" class="text-xs text-gray-500"></p>
107
  </div>
108
  </div>
@@ -178,16 +178,16 @@
178
 
179
  <div class="flex items-center">
180
  <input type="checkbox" id="transparentBg" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
181
- <label for="transparentBg" class="ml-2 block text-sm text-gray-700">Transparent background</label>
182
  </div>
183
 
184
  <div class="flex items-center">
185
  <input type="checkbox" id="optimizePaths" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded" checked>
186
- <label for="optimizePaths" class="ml-2 block text-sm text-gray-700">Optimize paths</label>
187
  </div>
188
  </div>
189
 
190
- <button id="convertBtn" class="w-full bg-indigo-600 hover:bg-indigo-7text-white py-2 px-4 rounded-md font-medium transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
191
  <i class="fas fa-magic mr-2"></i> Convert to SVG
192
  </button>
193
  </div>
@@ -310,6 +310,7 @@
310
  let currentFile = null;
311
  let canvas = document.createElement('canvas');
312
  let ctx = canvas.getContext('2d');
 
313
 
314
  // Toggle settings panel
315
  settingsToggle.addEventListener('click', () => {
@@ -461,6 +462,11 @@
461
  convertBtn.disabled = true;
462
  emptyState.classList.remove('hidden');
463
  resultContainer.classList.add('hidden');
 
 
 
 
 
464
  }
465
 
466
  // Process image with vectorization
@@ -470,17 +476,28 @@
470
  emptyState.classList.add('hidden');
471
  resultContainer.classList.add('hidden');
472
 
473
- // Simulate progress
 
 
 
474
  let progress = 0;
475
- const progressInterval = setInterval(() => {
476
- progress += Math.random() * 10;
477
- if (progress > 100) progress = 100; // Changed from 90 to 100
478
- progressBar.style.width = progress + '%';
 
 
 
 
 
479
 
480
- // Clear interval when we reach 100%
481
  if (progress >= 100) {
 
482
  clearInterval(progressInterval);
483
  }
 
 
484
  }, 200);
485
 
486
  // Process image after a short delay to allow UI to update
@@ -526,11 +543,21 @@
526
  });
527
 
528
  potrace.process(() => {
 
 
 
 
 
 
 
 
529
  // Get SVG data
530
  const svg = potrace.getSVG(1, settings.transparent ? 'none' : '#ffffff');
531
 
532
- // Show result
533
- showResult(svg);
 
 
534
  });
535
  }, 500);
536
  }
 
102
  <div class="bg-gray-100 rounded-lg p-3 flex items-center">
103
  <i class="fas fa-file-image text-indigo-500 text-xl mr-3"></i>
104
  <div>
105
+ <p id="fileName" class="text-sm font-medium text-gray-7truncate max-w-xs"></p>
106
  <p id="fileSize" class="text-xs text-gray-500"></p>
107
  </div>
108
  </div>
 
178
 
179
  <div class="flex items-center">
180
  <input type="checkbox" id="transparentBg" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
181
+ <label for="transparentBg" class="ml-2 block text-sm text-gray-7">Transparent background</label>
182
  </div>
183
 
184
  <div class="flex items-center">
185
  <input type="checkbox" id="optimizePaths" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded" checked>
186
+ <label for="optimizePaths" class="ml-2 block text-sm text-gray-7">Optimize paths</label>
187
  </div>
188
  </div>
189
 
190
+ <button id="convertBtn" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white py-2 px-4 rounded-md font-medium transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
191
  <i class="fas fa-magic mr-2"></i> Convert to SVG
192
  </button>
193
  </div>
 
310
  let currentFile = null;
311
  let canvas = document.createElement('canvas');
312
  let ctx = canvas.getContext('2d');
313
+ let progressInterval;
314
 
315
  // Toggle settings panel
316
  settingsToggle.addEventListener('click', () => {
 
462
  convertBtn.disabled = true;
463
  emptyState.classList.remove('hidden');
464
  resultContainer.classList.add('hidden');
465
+
466
+ // Clear any existing progress interval
467
+ if (progressInterval) {
468
+ clearInterval(progressInterval);
469
+ }
470
  }
471
 
472
  // Process image with vectorization
 
476
  emptyState.classList.add('hidden');
477
  resultContainer.classList.add('hidden');
478
 
479
+ // Reset progress bar
480
+ progressBar.style.width = '0%';
481
+
482
+ // Simulate progress with more controlled increments
483
  let progress = 0;
484
+ progressInterval = setInterval(() => {
485
+ // Calculate progress increment based on remaining distance to 100%
486
+ const remaining = 100 - progress;
487
+ const increment = Math.min(
488
+ Math.max(1, Math.floor(remaining * 0.15)), // Minimum 1%, maximum 15% of remaining
489
+ 10 // Absolute maximum increment per step
490
+ );
491
+
492
+ progress += increment;
493
 
494
+ // Ensure we don't go over 100%
495
  if (progress >= 100) {
496
+ progress = 100;
497
  clearInterval(progressInterval);
498
  }
499
+
500
+ progressBar.style.width = progress + '%';
501
  }, 200);
502
 
503
  // Process image after a short delay to allow UI to update
 
543
  });
544
 
545
  potrace.process(() => {
546
+ // Clear the progress interval if it's still running
547
+ if (progressInterval) {
548
+ clearInterval(progressInterval);
549
+ }
550
+
551
+ // Ensure progress bar shows 100%
552
+ progressBar.style.width = '100%';
553
+
554
  // Get SVG data
555
  const svg = potrace.getSVG(1, settings.transparent ? 'none' : '#ffffff');
556
 
557
+ // Show result after a small delay to allow progress bar to complete
558
+ setTimeout(() => {
559
+ showResult(svg);
560
+ }, 100);
561
  });
562
  }, 500);
563
  }