thelip commited on
Commit
b8d8086
·
verified ·
1 Parent(s): 2ecd1bc

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +14 -6
index.html CHANGED
@@ -5,13 +5,13 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Advanced Photo to SVG Converter</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
- <!-- Use the Potrace library that supports color tracing directly -->
9
- <!-- Added defer attribute -->
10
- <script src="https://unpkg.com/[email protected]/dist/potrace-wasm.js" defer></script>
11
  <!-- Quantize is less critical now but kept for potential future use/reference -->
12
  <!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quantize.min.js" defer></script> -->
13
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
14
  <style>
 
15
  .dropzone { border: 3px dashed rgba(59, 130, 246, 0.5); transition: all 0.3s ease; }
16
  .dropzone.active { border-color: rgba(59, 130, 246, 1); background-color: rgba(59, 130, 246, 0.1); }
17
  .canvas-container { position: relative; overflow: hidden; user-select: none; /* Prevent text selection during drag */ }
@@ -36,7 +36,7 @@
36
 
37
  /* Style for the SVG code preview */
38
  #svg-code-container { background-color: #f9fafb; border: 1px solid #e5e7eb; border-radius: 0.375rem; max-height: 200px; overflow: auto; padding: 0.5rem; }
39
- #svg-code { font-family: monospace; font-size: 0.75rem; color: #1f2937; white-space: pre-wrap; word-break: break-all; }
40
  </style>
41
  </head>
42
  <body class="bg-gray-50 min-h-screen">
@@ -392,12 +392,17 @@
392
 
393
  try {
394
  // --- Check & Load Potrace WASM ---
 
395
  if (typeof PotraceWasm === 'undefined') {
 
 
396
  throw new Error("PotraceWasm library failed to load. Check browser console and network connection.");
397
  }
398
 
399
  updateProgress(5, "Loading converter module...");
400
- await PotraceWasm.load(); // Ensures WASM is ready
 
 
401
  updateProgress(10, "Processing image data...");
402
 
403
  // --- Prepare parameters for potrace-wasm ---
@@ -431,7 +436,7 @@
431
  updateProgress(100, "Complete");
432
 
433
  } catch (error) {
434
- console.error('SVG Conversion Error:', error);
435
  const errorMsg = (error instanceof Error) ? error.message : String(error);
436
  alert(`Conversion failed: ${errorMsg}`);
437
  updateProgress(0, "Error");
@@ -439,6 +444,7 @@
439
  loadingIndicator.classList.add('hidden');
440
  progressContainer.classList.remove('hidden'); // Keep progress bar visible showing error state
441
  previewPlaceholder.classList.remove('hidden'); // Show placeholder again on error
 
442
  } finally {
443
  // --- UI Updates: End Conversion ---
444
  // Re-enable button only if an image is still loaded
@@ -449,6 +455,8 @@
449
  setTimeout(() => {
450
  progressContainer.classList.add('hidden');
451
  }, 1500);
 
 
452
  }
453
  }
454
  }
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Advanced Photo to SVG Converter</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
+ <!-- Switched to jsDelivr CDN -->
9
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/potrace-wasm.js" defer></script>
 
10
  <!-- Quantize is less critical now but kept for potential future use/reference -->
11
  <!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quantize.min.js" defer></script> -->
12
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
13
  <style>
14
+ /* Styles remain the same as before - truncated for brevity */
15
  .dropzone { border: 3px dashed rgba(59, 130, 246, 0.5); transition: all 0.3s ease; }
16
  .dropzone.active { border-color: rgba(59, 130, 246, 1); background-color: rgba(59, 130, 246, 0.1); }
17
  .canvas-container { position: relative; overflow: hidden; user-select: none; /* Prevent text selection during drag */ }
 
36
 
37
  /* Style for the SVG code preview */
38
  #svg-code-container { background-color: #f9fafb; border: 1px solid #e5e7eb; border-radius: 0.375rem; max-height: 200px; overflow: auto; padding: 0.5rem; }
39
+ #svg-code-el { font-family: monospace; font-size: 0.75rem; color: #1f2937; white-space: pre-wrap; word-break: break-all; }
40
  </style>
41
  </head>
42
  <body class="bg-gray-50 min-h-screen">
 
392
 
393
  try {
394
  // --- Check & Load Potrace WASM ---
395
+ // THIS IS THE CRITICAL CHECK
396
  if (typeof PotraceWasm === 'undefined') {
397
+ // If this error happens, the script from the CDN likely failed to load or execute.
398
+ console.error("PotraceWasm global object is not defined. Script load failed?");
399
  throw new Error("PotraceWasm library failed to load. Check browser console and network connection.");
400
  }
401
 
402
  updateProgress(5, "Loading converter module...");
403
+ // PotraceWasm.load() might return a promise, ensure it's awaited.
404
+ // It handles loading the actual WASM binary.
405
+ await PotraceWasm.load();
406
  updateProgress(10, "Processing image data...");
407
 
408
  // --- Prepare parameters for potrace-wasm ---
 
436
  updateProgress(100, "Complete");
437
 
438
  } catch (error) {
439
+ console.error('SVG Conversion Error:', error); // Log the full error object
440
  const errorMsg = (error instanceof Error) ? error.message : String(error);
441
  alert(`Conversion failed: ${errorMsg}`);
442
  updateProgress(0, "Error");
 
444
  loadingIndicator.classList.add('hidden');
445
  progressContainer.classList.remove('hidden'); // Keep progress bar visible showing error state
446
  previewPlaceholder.classList.remove('hidden'); // Show placeholder again on error
447
+ comparisonContainer.classList.add('hidden'); // Ensure comparison view is hidden on error
448
  } finally {
449
  // --- UI Updates: End Conversion ---
450
  // Re-enable button only if an image is still loaded
 
455
  setTimeout(() => {
456
  progressContainer.classList.add('hidden');
457
  }, 1500);
458
+ } else {
459
+ // Don't automatically hide progress bar on error
460
  }
461
  }
462
  }