Docfile commited on
Commit
f9e66d0
·
verified ·
1 Parent(s): ecb5f6f

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +388 -198
templates/index.html CHANGED
@@ -3,215 +3,226 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Mariam Espagnol - Analyse Polaire Fascinante!</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://unpkg.com/[email protected]/marked.min.js"></script>
 
9
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
 
10
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/prism.min.js" integrity="sha512-7Z9J3l1+EYfeaPKcGXu3MS/7SluIYINAaicZN83z9/9XjUhIYU/YHwZxpTBIlXgy9XEOXRJW1QQkAcLpbzm7hA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
11
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/themes/prism-tomorrow.min.css" integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXOyEVrd0XB9aLhtFOUUjLz90GzvnBCgXWLSntyo7w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
 
12
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-core.min.js" integrity="sha512-9khQRAUBYEJDCDVP2ywQ0LRUbnjL3ZfrPJorj7MF8+KEvn3chLJniiG9LUDXTQGshyrGXxGzvSgKyYad7is+7Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
13
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-GP4x8UWxWyh4BMbyJGOGneiTbUdnpcBtDbJcdM8XcSzaHjMTzOL/zENvu6QRGxzNssVSKHncmXbvH/SsqR2nLw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
14
 
15
  <style>
16
  @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Poppins:wght@300;400;500;600&display=swap');
17
 
18
- html, body { height: 100%; } /* Assurer que html et body peuvent prendre toute la hauteur */
19
-
20
  body {
21
  font-family: 'Poppins', sans-serif;
22
- background: linear-gradient(45deg, #e0f7fa, #d1c4e9, #f8bbd0, #bbdefb);
23
- background-size: 400% 400%;
24
- animation: gradientBG 15s ease infinite;
25
- display: flex; /* Utiliser Flexbox pour le body */
26
- flex-direction: column; /* Empiler les enfants verticalement */
27
  }
28
  h1, h2, h3, h4, h5, h6 {
29
  font-family: 'Playfair Display', serif;
30
  }
31
 
32
- @keyframes gradientBG { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
33
- .fade-in { animation: fadeIn 0.7s ease-in forwards; }
34
- .slide-up { animation: slideUp 0.6s ease-out forwards; opacity: 0; }
35
- .pop-in { animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards; opacity: 0; }
36
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
37
- @keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
38
- @keyframes popIn { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
39
- @keyframes pulse { 0%, 100% { transform: scale(1); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06); } 50% { transform: scale(1.03); box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3), 0 4px 6px -2px rgba(79, 70, 229, 0.2); } }
40
- @keyframes wiggle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
41
-
42
- .gradient-text { background: linear-gradient(45deg, #7928CA, #FF0080, #42A5F5); -webkit-background-clip: text; background-clip: text; color: transparent; }
43
-
44
- .upload-zone { background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(5px); border: 3px dashed #a5b4fc; border-radius: 1.5rem; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08); transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
45
- .upload-zone:hover, .upload-zone.dragover { border-color: #6366f1; background: rgba(255, 255, 255, 0.9); transform: translateY(-5px) scale(1.03); box-shadow: 0 12px 25px rgba(99, 102, 241, 0.2); }
46
- .upload-zone:hover .upload-icon { animation: wiggle 0.5s ease-in-out infinite; }
47
-
48
- #submit-button:not(:disabled) { background: linear-gradient(45deg, #4f46e5, #7c3aed); background-size: 200% 200%; animation: gradientBG 5s ease infinite reverse, pulse 2s infinite; transition: transform 0.2s ease; }
49
- #submit-button:not(:disabled):hover { transform: scale(1.05); }
50
-
51
- /* Loader Pingouin Styles */
52
- #penguin-loader { position: fixed; inset: 0; background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 100; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
53
- #penguin-loader.visible { opacity: 1; visibility: visible; }
54
- .penguin { width: 150px; height: 150px; position: relative; animation: waddle 1.2s linear infinite; }
55
- .penguin-body { width: 90px; height: 120px; background-color: #2c3e50; border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); box-shadow: 0 4px 8px rgba(0,0,0,0.2); }
56
- .penguin-belly { width: 65px; height: 80px; background-color: white; border-radius: 50%; position: absolute; top: 20px; left: 50%; transform: translateX(-50%); }
57
- .penguin-eye { width: 10px; height: 10px; background-color: white; border-radius: 50%; position: absolute; top: 40px; box-shadow: inset 2px 2px 0 #2c3e50; }
58
- .penguin-eye.left { left: 25px; } .penguin-eye.right { right: 25px; }
59
- .penguin-beak { width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-top: 15px solid #f39c12; position: absolute; top: 55px; left: 50%; transform: translateX(-50%); }
60
- .penguin-flipper { width: 25px; height: 50px; background-color: #34495e; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; position: absolute; top: 50px; transform-origin: top center; }
61
- .penguin-flipper.left { left: 5px; transform: rotate(-30deg); animation: flap-left 1.2s linear infinite; }
62
- .penguin-flipper.right { right: 5px; transform: rotate(30deg); animation: flap-right 1.2s linear infinite; }
63
- .penguin-foot { width: 25px; height: 15px; background-color: #f39c12; border-radius: 50% 50% 0 0; position: absolute; bottom: -5px; }
64
- .penguin-foot.left { left: 35px; transform: rotate(-15deg); } .penguin-foot.right { right: 35px; transform: rotate(15deg); }
65
- @keyframes waddle { 0%, 100% { transform: rotate(2deg); } 50% { transform: rotate(-2deg); } }
66
- @keyframes flap-left { 0%, 100% { transform: rotate(-30deg); } 50% { transform: rotate(-10deg); } }
67
- @keyframes flap-right { 0%, 100% { transform: rotate(30deg); } 50% { transform: rotate(10deg); } }
68
- .loading-text { font-family: 'Poppins', sans-serif; margin-top: 170px; font-size: 1.1em; color: #34495e; font-weight: 500; text-align: center; }
69
-
70
- #results.pop-in { animation: popIn 0.6s 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; opacity: 0; }
71
-
72
- /* Prism et Prose */
73
- .prose pre[class*="language-"] { background-color: #2d2d2d !important; color: #ccc; padding: 1em; margin: 1.5em 0; overflow-x: auto; border-radius: 0.5rem; border: 1px solid #444; }
74
- .prose code[class*="language-"] { font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; color: #ccc; background: none; text-shadow: none; font-size: 0.9em; direction: ltr; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; }
75
- .prose :not(pre) > code { background-color: #e0e7ff; color: #4338ca; padding: 0.2em 0.4em; border-radius: 0.25rem; font-size: 0.9em; }
76
- .prose h1, .prose h2, .prose h3 { color: #1F2937; margin-top: 1.5em; margin-bottom: 0.8em; padding-bottom: 0.3em; border-bottom: 1px solid #d1d5db; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  .prose p { margin-bottom: 1.25em; line-height: 1.7; }
78
  .prose ul, .prose ol { margin-left: 1.5em; margin-bottom: 1.25em; }
79
  .prose li > p { margin-bottom: 0.5em; }
80
- button:disabled { opacity: 0.5; cursor: not-allowed; background: #a5b4fc !important; animation: none !important; }
81
- :not(pre) > code[class*="language-"], pre[class*="language-"] { background: #2d2d2d; }
82
-
83
- /* Styles pour la mise en page pleine hauteur */
84
- .main-wrapper {
85
- flex-grow: 1; /* Permet à ce conteneur de prendre l'espace restant */
86
- display: flex;
87
- flex-direction: column;
88
  }
89
- .content-card {
90
- flex-grow: 1; /* Permet à la carte de contenu de s'étendre */
91
- /* Optionnel: ajouter un min-height si nécessaire pour éviter qu'elle soit trop petite */
92
- /* min-height: 400px; */
93
  }
94
-
95
  </style>
96
  </head>
97
- <!-- Ajout de flex flex-col min-h-screen au body -->
98
- <body class="min-h-screen relative overflow-x-hidden flex flex-col">
99
-
100
- <!-- Penguin Loader -->
101
- <div id="penguin-loader" class="">
102
- <div class="penguin">
103
- <div class="penguin-body"> <div class="penguin-belly"></div> <div class="penguin-eye left"></div> <div class="penguin-eye right"></div> <div class="penguin-beak"></div> </div>
104
- <div class="penguin-flipper left"></div> <div class="penguin-flipper right"></div> <div class="penguin-foot left"></div> <div class="penguin-foot right"></div>
105
- <div class="loading-text">Analyse Polaire en cours...</div>
106
- </div>
107
  </div>
108
 
109
- <!-- Conteneur principal pour Flexbox pleine hauteur -->
110
- <!-- Ajout de flex-grow flex flex-col -->
111
- <div class="main-wrapper max-w-4xl w-full mx-auto px-4 py-12 relative z-10 flex flex-col flex-grow">
112
-
113
  <!-- Header -->
114
- <header class="text-center mb-12 fade-in" style="animation-delay: 0.1s;">
115
- <h1 class="text-4xl md:text-5xl font-bold mb-3 font-['Playfair_Display'] gradient-text">
116
  Mariam Espagnol
117
  </h1>
118
- <p class="text-lg text-gray-800 font-light max-w-xl mx-auto">
119
- Votre copilote pour des analyses fascinantes de documents!
120
  </p>
121
  </header>
122
 
123
- <!-- Main Content Card - Ajout de flex-grow -->
124
- <div class="content-card bg-white/80 backdrop-blur-md rounded-3xl shadow-xl p-6 md:p-8 mb-8 pop-in flex-grow" style="animation-delay: 0.3s;">
125
- <!-- File Type Selection -->
126
  <div class="mb-6">
127
- <label class="block text-base font-medium text-gray-700 mb-3">1. Type de mission ?</label>
128
  <div class="flex flex-col sm:flex-row gap-4">
129
- <label class="relative flex items-center group cursor-pointer p-3 border border-gray-200 rounded-xl hover:bg-indigo-50 transition-colors w-full hover:shadow-sm">
130
- <input type="radio" name="fileType" value="image" checked class="peer sr-only file-type-radio">
131
- <div class="w-5 h-5 mr-3 border-2 border-indigo-200 rounded-full flex-shrink-0 peer-checked:border-indigo-500 peer-checked:bg-indigo-500 transition-all transform peer-checked:scale-110"></div>
132
- <!-- **** LABEL MODIFIÉ **** -->
133
- <span class="text-sm text-gray-700 group-hover:text-indigo-600 font-medium">Document iconographique (avec méthodologie)</span>
134
  </label>
135
- <label class="relative flex items-center group cursor-pointer p-3 border border-gray-200 rounded-xl hover:bg-indigo-50 transition-colors w-full hover:shadow-sm">
136
- <input type="radio" name="fileType" value="text" class="peer sr-only file-type-radio">
137
- <div class="w-5 h-5 mr-3 border-2 border-indigo-200 rounded-full flex-shrink-0 peer-checked:border-indigo-500 peer-checked:bg-indigo-500 transition-all transform peer-checked:scale-110"></div>
138
- <!-- **** LABEL MODIFIÉ **** -->
139
- <span class="text-sm text-gray-700 group-hover:text-indigo-600 font-medium">Document textuel (avec méthodologie)</span>
140
  </label>
141
  </div>
142
  </div>
143
 
144
- <!-- Upload Zone -->
145
  <div class="mb-6">
146
- <label class="block text-base font-medium text-gray-700 mb-3">2. Le document secret ?</label>
147
- <div id="upload-zone" class="upload-zone p-6 text-center cursor-pointer relative overflow-hidden">
148
  <input id="file-upload" name="file" type="file" class="sr-only" accept="image/*">
149
- <div class="space-y-3 flex flex-col items-center justify-center">
150
- <div class="upload-icon w-16 h-16 mx-auto rounded-full bg-indigo-100 flex items-center justify-center border-4 border-white shadow-sm transition-transform duration-300">
151
- <svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/> </svg>
 
 
152
  </div>
153
- <div class="text-sm text-gray-600">
154
- <label for="file-upload" class="relative cursor-pointer rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500"> <span class="font-semibold">Déposez le fichier ici</span> </label>
 
 
155
  <span class="text-gray-500"> ou </span>
156
- <label for="file-upload" class="cursor-pointer text-indigo-600 hover:text-indigo-500 font-medium">cliquez pour explorer</label>
157
  </div>
158
- <p class="text-xs text-gray-500" id="file-types-info">Images (PNG, JPG...) ou Textes (TXT, PDF) - Max 16MB</p>
159
  </div>
160
  </div>
161
  </div>
162
 
163
- <!-- Preview -->
164
- <div id="preview" class="mt-6 hidden pop-in">
165
- <h3 class="text-base font-medium text-gray-800 mb-3">Aperçu de la cible :</h3>
166
- <div class="preview-container border border-indigo-100 rounded-xl p-4 bg-indigo-50/50 max-h-72 overflow-auto relative shadow-inner">
167
- <img id="image-preview" class="max-w-full h-auto hidden rounded-lg block mx-auto shadow-md" alt="Aperçu Image">
168
- <pre id="text-preview" class="text-sm text-gray-700 whitespace-pre-wrap hidden bg-white/80 p-3 rounded-lg shadow"></pre>
169
- <p id="file-info" class="text-xs text-indigo-800 mt-2 text-center font-medium"></p>
170
- <button id="remove-file-button" class="absolute top-2 right-2 bg-red-500 text-white hover:bg-red-600 rounded-full p-1.5 text-xs shadow-md transform transition hover:scale-110" title="Annuler la mission">
171
- <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3"> <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /> </svg>
 
 
172
  </button>
173
  </div>
174
  </div>
175
 
176
- <!-- Submit Button -->
177
- <div class="mt-8 text-center">
178
- <button id="submit-button" disabled class="text-white font-semibold py-3 px-8 rounded-xl shadow-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition duration-150 ease-in-out disabled:opacity-50 disabled:cursor-not-allowed disabled:bg-indigo-300">
179
- <span id="submit-button-text">3. Déclencher l'Analyse Polaire !</span>
180
- <span id="submit-button-spinner" class="hidden items-center">
181
- <svg class="animate-spin inline-block -ml-1 mr-2 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path> </svg>
182
- Calcul en cours...
 
 
 
 
 
183
  </span>
184
  </button>
185
  </div>
186
 
187
  <!-- Analysis Results -->
188
- <div id="results" class="mt-10 hidden">
189
- <h3 class="text-lg font-semibold text-gray-900 mb-4 border-b border-indigo-200 pb-2">Rapport d'Analyse :</h3>
190
- <div class="bg-white/70 backdrop-blur-sm rounded-xl p-4 md:p-6 shadow-inner overflow-x-auto border border-gray-200">
 
191
  <div id="analysis-content" class="prose prose-sm sm:prose-base max-w-none prose-indigo">
192
- <p class="text-gray-500">Le rapport fascinant apparaîtra ici...</p>
193
  </div>
194
  </div>
195
  <div class="mt-4 text-right">
196
- <button id="copy-analysis-button" class="text-sm bg-indigo-100 hover:bg-indigo-200 text-indigo-700 font-medium py-1.5 px-4 rounded-lg transition duration-150 ease-in-out shadow-sm hover:shadow">
197
- Copier le Rapport
198
  </button>
199
  </div>
200
  </div>
 
201
 
202
- </div> <!-- End content-card -->
203
-
204
- <!-- Footer -->
205
- <footer class="text-center mt-auto pt-8 text-gray-700 text-sm fade-in" style="animation-delay: 0.5s;"> <!-- mt-auto pousse le footer en bas -->
206
- <p>© 2025 Mariam Espagnol - Expédition Analytique Polaire</p>
207
  </footer>
208
 
209
- </div> <!-- End main-wrapper -->
210
-
211
 
212
  <script>
213
  document.addEventListener('DOMContentLoaded', function() {
214
- // --- DOM Elements ---
215
  const uploadZone = document.getElementById('upload-zone');
216
  const fileInput = document.getElementById('file-upload');
217
  const preview = document.getElementById('preview');
@@ -227,124 +238,303 @@
227
  const copyAnalysisButton = document.getElementById('copy-analysis-button');
228
  const fileTypeRadios = document.querySelectorAll('.file-type-radio');
229
  const fileTypesInfo = document.getElementById('file-types-info');
230
- const penguinLoader = document.getElementById('penguin-loader');
231
 
232
  let selectedFile = null;
233
 
234
- // --- Configurations ---
235
- marked.setOptions({
236
- breaks: true, gfm: true, headerIds: false, mangle: false,
 
 
 
237
  highlight: function(code, lang) {
 
238
  if (typeof Prism !== 'undefined' && Prism.languages[lang]) {
239
- try { return Prism.highlight(code, Prism.languages[lang], lang); }
240
- catch (error) { console.warn(`Prism highlight failed:`, error); return code; }
 
 
 
 
241
  }
 
242
  return code;
243
  }
244
  });
245
 
246
- // --- Helper Functions ---
247
- function showPenguinLoader(isLoading) {
248
- if (isLoading) { penguinLoader.classList.add('visible'); }
249
- else { penguinLoader.classList.remove('visible'); }
250
- }
251
- function showButtonLoading(isLoading) {
252
- if (isLoading) { submitButtonText.classList.add('hidden'); submitButtonSpinner.classList.remove('hidden'); submitButton.disabled = true; }
253
- else { submitButtonText.classList.remove('hidden'); submitButtonSpinner.classList.add('hidden'); submitButton.disabled = (selectedFile === null); }
 
 
 
254
  }
 
255
  function resetUI() {
256
- selectedFile = null; fileInput.value = '';
257
- preview.classList.add('hidden'); imagePreview.classList.add('hidden'); textPreview.classList.add('hidden');
258
- imagePreview.src = '#'; textPreview.textContent = ''; fileInfo.textContent = '';
 
 
 
 
 
259
  removeFileButton.classList.add('hidden');
260
- results.classList.add('hidden'); results.classList.remove('pop-in');
261
- analysisContent.innerHTML = '<p class="text-gray-500">Le rapport fascinant apparaîtra ici...</p>';
262
- submitButton.disabled = true; showButtonLoading(false); updateAcceptAttribute();
 
 
263
  }
264
- function updateAcceptAttribute() {
 
265
  const selectedType = document.querySelector('input[name="fileType"]:checked').value;
266
- if (selectedType === 'image') { fileInput.accept = "image/png, image/jpeg, image/gif, image/webp"; fileTypesInfo.textContent = "Images (PNG, JPG, GIF, WEBP) - Max 16MB"; }
267
- else { fileInput.accept = "text/plain, application/pdf, .txt"; fileTypesInfo.textContent = "Textes (TXT, PDF lisible) - Max 16MB"; }
 
 
 
 
 
268
  if (selectedFile) {
269
- const currentFileTypeMatchesSelection = (selectedType === 'image' && selectedFile.type.startsWith('image/')) || (selectedType === 'text' && (selectedFile.type === 'text/plain' || selectedFile.type === 'application/pdf' || selectedFile.name.endsWith('.txt')));
 
 
 
270
  if(!currentFileTypeMatchesSelection) {
271
- resetUI(); Swal.fire({ icon: 'warning', title: 'Type changé !', text: 'Mission reconfigurée. Veuillez re-sélectionner votre document.', });
 
 
 
 
 
 
272
  }
273
  }
274
  }
275
 
 
276
  // --- Event Listeners ---
277
- fileTypeRadios.forEach(radio => radio.addEventListener('change', updateAcceptAttribute));
 
 
278
  uploadZone.addEventListener('click', () => fileInput.click());
279
- uploadZone.addEventListener('dragover', (e) => { e.preventDefault(); uploadZone.classList.add('dragover'); });
280
- uploadZone.addEventListener('dragleave', () => uploadZone.classList.remove('dragover'));
281
- uploadZone.addEventListener('drop', (e) => { e.preventDefault(); uploadZone.classList.remove('dragover'); if (e.dataTransfer.files.length) handleFileSelection(e.dataTransfer.files[0]); });
282
- fileInput.addEventListener('change', (e) => { if (e.target.files.length) handleFileSelection(e.target.files[0]); });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  removeFileButton.addEventListener('click', resetUI);
284
  submitButton.addEventListener('click', handleSubmit);
285
  copyAnalysisButton.addEventListener('click', copyAnalysisToClipboard);
286
 
287
- // --- Core Logic ---
 
 
288
  function handleFileSelection(file) {
 
289
  const maxFileSize = 16 * 1024 * 1024;
290
- if (file.size > maxFileSize) { Swal.fire({ icon: 'error', title: 'Trop Lourd !', text: `Max 16 Mo autorisé. Votre fichier fait ${(file.size / 1024 / 1024).toFixed(1)} Mo.` }); resetUI(); return; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  selectedFile = file;
292
- preview.classList.remove('hidden'); preview.style.animation = 'none'; void preview.offsetWidth; preview.style.animation = ''; preview.classList.add('pop-in');
293
- results.classList.add('hidden'); results.classList.remove('pop-in');
294
- analysisContent.innerHTML = '<p class="text-gray-500">Le rapport fascinant apparaîtra ici...</p>';
 
295
  fileInfo.textContent = `${file.name} (${(file.size / 1024).toFixed(1)} Ko)`;
296
  removeFileButton.classList.remove('hidden');
297
- const fileType = document.querySelector('input[name="fileType"]:checked').value;
298
  if (fileType === 'image') {
299
- imagePreview.classList.remove('hidden'); textPreview.classList.add('hidden');
300
- const reader = new FileReader(); reader.onload = (e) => imagePreview.src = e.target.result; reader.readAsDataURL(file);
 
 
 
301
  } else {
302
- imagePreview.classList.add('hidden'); textPreview.classList.remove('hidden');
303
- if (file.type === 'application/pdf') { textPreview.textContent = "Aperçu PDF non disponible ici."; }
304
- else { const reader = new FileReader(); reader.onload = (e) => textPreview.textContent = e.target.result; reader.readAsText(file); }
 
 
 
 
 
 
305
  }
306
  submitButton.disabled = false;
307
  }
308
 
309
  function handleSubmit() {
310
- if (!selectedFile) { Swal.fire('Oups !', 'Il faut un document secret pour lancer l\'analyse.', 'warning'); return; }
 
 
 
 
311
  const fileType = document.querySelector('input[name="fileType"]:checked').value;
312
- const formData = new FormData(); formData.append('file', selectedFile); formData.append('fileType', fileType);
313
- showPenguinLoader(true); showButtonLoading(true); results.classList.add('hidden'); results.classList.remove('pop-in');
314
- fetch('/upload', { method: 'POST', body: formData })
 
 
 
 
 
 
 
 
315
  .then(response => {
316
- if (!response.ok) { return response.json().then(errData => { throw new Error(errData.error || `Erreur HTTP: ${response.status}`); }).catch(() => { throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`); }); }
 
 
 
 
 
 
317
  return response.json();
318
  })
319
  .then(data => {
320
- showPenguinLoader(false); showButtonLoading(false);
321
  if (data.success && data.analysis) {
322
- results.classList.remove('hidden'); results.style.animation = 'none'; void results.offsetWidth; results.style.animation = ''; results.classList.add('pop-in');
 
323
  analysisContent.innerHTML = marked.parse(data.analysis);
324
- if (typeof Prism !== 'undefined') { analysisContent.querySelectorAll('pre code').forEach((block) => { Prism.highlightElement(block); }); } else { console.warn("Prism n'est pas chargé."); }
 
 
 
 
 
 
 
 
 
 
 
 
325
  results.scrollIntoView({ behavior: 'smooth', block: 'start' });
326
- } else { throw new Error(data.error || "L'analyse a échoué, le pingouin est confus."); }
 
 
327
  })
328
  .catch(error => {
329
- showPenguinLoader(false); showButtonLoading(false);
330
- Swal.fire({ icon: 'error', title: 'Erreur Glaciale !', text: error.message || 'Une erreur inconnue a gelé le processus.', });
331
- console.error('Error during analysis:', error); submitButton.disabled = false;
 
 
 
 
 
 
 
332
  });
333
  }
334
 
335
- function copyAnalysisToClipboard() {
336
- const analysisHtml = analysisContent.innerHTML;
337
- if (!analysisHtml || analysisContent.textContent.includes('Le rapport fascinant apparaîtra ici...')) { Swal.fire('Vide !', 'Rien à copier. Lancez une analyse !', 'info'); return; }
338
- const tempDiv = document.createElement('div'); tempDiv.innerHTML = analysisHtml;
339
- let textToCopy = tempDiv.textContent || tempDiv.innerText || "";
340
- textToCopy = analysisHtml.replace(/<br\s*\/?>/gi, '\n').replace(/<\/p>/gi, '\n').replace(/<\/li>/gi, '\n').replace(/<\/(h[1-6])>/gi, '\n\n').replace(/<pre.*?><code.*?>([\s\S]*?)<\/code><\/pre>/gi, '\n```\n$1\n```\n').replace(/<[^>]+>/g, '').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').trim();
341
- navigator.clipboard.writeText(textToCopy).then(() => { Swal.fire({ icon: 'success', title: 'Copié !', text: 'Rapport secret copié !', timer: 1800, showConfirmButton: false, toast: true, position: 'top-end' }); })
342
- .catch(err => { console.error('Erreur copie: ', err); Swal.fire({ icon: 'error', title: 'Copie échouée', text: 'Impossible de copier. Essayez manuellement !' }); });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  }
344
 
 
345
  // --- Initial Setup ---
346
  updateAcceptAttribute();
347
  resetUI();
 
348
  }); // End DOMContentLoaded
349
  </script>
350
  </body>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Mariam Espagnol - Analyse de Documents</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://unpkg.com/[email protected]/marked.min.js"></script>
9
+ <!-- SweetAlert2 -->
10
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
11
+ <!-- PrismJS Core & Theme -->
12
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/prism.min.js" integrity="sha512-7Z9J3l1+EYfeaPKcGXu3MS/7SluIYINAaicZN83z9/9XjUhIYU/YHwZxpTBIlXgy9XEOXRJW1QQkAcLpbzm7hA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
13
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/themes/prism-tomorrow.min.css" integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXOyEVrd0XB9aLhtFOUUjLz90GzvnBCgXWLSntyo7w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
14
+ <!-- PrismJS Languages (Load components individually if needed, or use autoloader) -->
15
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-core.min.js" integrity="sha512-9khQRAUBYEJDCDVP2ywQ0LRUbnjL3ZfrPJorj7MF8+KEvn3chLJniiG9LUDXTQGshyrGXxGzvSgKyYad7is+7Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
16
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-GP4x8UWxWyh4BMbyJGOGneiTbUdnpcBtDbJcdM8XcSzaHjMTzOL/zENvu6QRGxzNssVSKHncmXbvH/SsqR2nLw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
17
 
18
  <style>
19
  @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Poppins:wght@300;400;500;600&display=swap');
20
 
 
 
21
  body {
22
  font-family: 'Poppins', sans-serif;
 
 
 
 
 
23
  }
24
  h1, h2, h3, h4, h5, h6 {
25
  font-family: 'Playfair Display', serif;
26
  }
27
 
28
+ .fade-in { animation: fadeIn 0.5s ease-in; }
29
+ .slide-up { animation: slideUp 0.5s ease-out; }
 
 
30
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
31
+ @keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
32
+
33
+ .gradient-text {
34
+ background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
35
+ -webkit-background-clip: text;
36
+ background-clip: text;
37
+ color: transparent;
38
+ }
39
+ .upload-zone {
40
+ background: linear-gradient(145deg, #f9fafb, #f3f4f6);
41
+ box-shadow: 5px 5px 15px #d1d9e6, -5px -5px 15px #ffffff;
42
+ transition: all 0.3s ease;
43
+ }
44
+ .upload-zone.dragover {
45
+ border-color: #4f46e5;
46
+ background: #e0e7ff;
47
+ transform: scale(1.02);
48
+ }
49
+ .waves { position: absolute; bottom: 0; left: 0; width: 100%; overflow: hidden; line-height: 0; transform: rotate(180deg); z-index: 0; }
50
+ .waves svg { position: relative; display: block; width: calc(100% + 1.3px); height: 150px; }
51
+ .waves .fill-indigo-50 { fill: #eef2ff; }
52
+
53
+ /* Responsive Analysis Box & Prose */
54
+ .prose { max-width: 100%; }
55
+ .prose pre[class*="language-"] { /* Target only Prism <pre> blocks */
56
+ background-color: #2d2d2d !important; /* Match Prism Tomorrow, use !important if needed */
57
+ color: #ccc;
58
+ padding: 1em;
59
+ margin: 1.5em 0;
60
+ overflow-x: auto;
61
+ border-radius: 0.375rem;
62
+ border: 1px solid #444; /* Subtle border */
63
+ }
64
+ .prose code[class*="language-"] { /* Target only Prism <code> blocks */
65
+ font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; /* Monospace font */
66
+ color: #ccc;
67
+ background: none;
68
+ text-shadow: none;
69
+ font-size: 0.9em; /* Slightly smaller code font */
70
+ direction: ltr;
71
+ text-align: left;
72
+ white-space: pre;
73
+ word-spacing: normal;
74
+ word-break: normal;
75
+ line-height: 1.5;
76
+ -moz-tab-size: 4;
77
+ -o-tab-size: 4;
78
+ tab-size: 4;
79
+ -webkit-hyphens: none;
80
+ -moz-hyphens: none;
81
+ -ms-hyphens: none;
82
+ hyphens: none;
83
+ }
84
+ /* Ensure inline code also gets styled if needed, but differently */
85
+ .prose :not(pre) > code {
86
+ background-color: #f3f4f6; /* Light gray background for inline code */
87
+ color: #4b5563; /* Darker gray text */
88
+ padding: 0.2em 0.4em;
89
+ border-radius: 0.25rem;
90
+ font-size: 0.9em;
91
+ }
92
+ .prose h1, .prose h2, .prose h3 { color: #1F2937; margin-top: 1.5em; margin-bottom: 0.8em; padding-bottom: 0.3em; border-bottom: 1px solid #e5e7eb; }
93
  .prose p { margin-bottom: 1.25em; line-height: 1.7; }
94
  .prose ul, .prose ol { margin-left: 1.5em; margin-bottom: 1.25em; }
95
  .prose li > p { margin-bottom: 0.5em; }
96
+ /* Button disabled state */
97
+ button:disabled {
98
+ opacity: 0.5;
99
+ cursor: not-allowed;
100
+ background-color: #a5b4fc;
 
 
 
101
  }
102
+ /* Fix potential Prism theme override from Tailwind */
103
+ :not(pre) > code[class*="language-"], pre[class*="language-"] {
104
+ background: #2d2d2d;
 
105
  }
 
106
  </style>
107
  </head>
108
+ <body class="bg-gradient-to-br from-gray-50 to-gray-100 min-h-screen relative overflow-x-hidden">
109
+ <div class="waves">
110
+ <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
111
+ <path d="M321.39,56.44c58-10.79,114.16-30.13,172-41.86,82.39-16.72,168.19-17.73,250.45-.39C823.78,31,906.67,72,985.66,92.83c70.05,18.48,146.53,26.09,214.34,3V0H0V27.35A600.21,600.21,0,0,0,321.39,56.44Z" class="fill-indigo-50"></path>
112
+ </svg>
 
 
 
 
 
113
  </div>
114
 
115
+ <div class="max-w-4xl mx-auto px-4 py-12 relative z-10">
 
 
 
116
  <!-- Header -->
117
+ <header class="text-center mb-12 fade-in">
118
+ <h1 class="text-4xl md:text-5xl font-bold mb-3 font-['Playfair_Display'] gradient-text">
119
  Mariam Espagnol
120
  </h1>
121
+ <p class="text-lg text-gray-600 font-light max-w-xl mx-auto">
122
+ Analysez vos documents iconographiques ou textuels en espagnol
123
  </p>
124
  </header>
125
 
126
+ <!-- Main Content -->
127
+ <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 mb-8 slide-up">
128
+ <!-- File Type Selection -->
129
  <div class="mb-6">
130
+ <label class="block text-base font-medium text-gray-700 mb-3">1. Choisissez le type de document</label>
131
  <div class="flex flex-col sm:flex-row gap-4">
132
+ <label class="relative flex items-center group cursor-pointer p-3 border border-gray-200 rounded-lg hover:bg-indigo-50 transition-colors w-full">
133
+ <input type="radio" name="fileType" value="image" checked
134
+ class="peer sr-only file-type-radio">
135
+ <div class="w-5 h-5 mr-3 border-2 border-gray-300 rounded-full flex-shrink-0 peer-checked:border-indigo-500 peer-checked:bg-indigo-500 transition-all"></div>
136
+ <span class="text-sm text-gray-700 group-hover:text-indigo-600">Document iconographique (Image, Photo, Dessin...) avec méthodologie.</span>
137
  </label>
138
+ <label class="relative flex items-center group cursor-pointer p-3 border border-gray-200 rounded-lg hover:bg-indigo-50 transition-colors w-full">
139
+ <input type="radio" name="fileType" value="text"
140
+ class="peer sr-only file-type-radio">
141
+ <div class="w-5 h-5 mr-3 border-2 border-gray-300 rounded-full flex-shrink-0 peer-checked:border-indigo-500 peer-checked:bg-indigo-500 transition-all"></div>
142
+ <span class="text-sm text-gray-700 group-hover:text-indigo-600">Document textuel (Texte, PDF lisible...) avec méthodologie.</span>
143
  </label>
144
  </div>
145
  </div>
146
 
147
+ <!-- Upload Zone -->
148
  <div class="mb-6">
149
+ <label class="block text-base font-medium text-gray-700 mb-3">2. Sélectionnez votre fichier</label>
150
+ <div id="upload-zone" class="upload-zone border-2 border-dashed border-gray-300 rounded-xl p-6 text-center cursor-pointer transition-all duration-300 relative overflow-hidden">
151
  <input id="file-upload" name="file" type="file" class="sr-only" accept="image/*">
152
+ <div class="space-y-3">
153
+ <div class="w-16 h-16 mx-auto rounded-full bg-indigo-100 flex items-center justify-center border-4 border-white shadow-sm">
154
+ <svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
155
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
156
+ </svg>
157
  </div>
158
+ <div class="text-sm text-gray-600">
159
+ <label for="file-upload" class="relative cursor-pointer rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500">
160
+ <span>Déposez votre fichier ici</span>
161
+ </label>
162
  <span class="text-gray-500"> ou </span>
163
+ <label for="file-upload" class="cursor-pointer text-indigo-600 hover:text-indigo-500 font-medium">cliquez pour sélectionner</label>
164
  </div>
165
+ <p class="text-xs text-gray-500" id="file-types-info">Images (PNG, JPG, GIF) ou Textes (TXT, PDF) - Max 16MB</p>
166
  </div>
167
  </div>
168
  </div>
169
 
170
+ <!-- Preview -->
171
+ <div id="preview" class="mt-6 hidden slide-up">
172
+ <h3 class="text-base font-medium text-gray-800 mb-3">Aperçu</h3>
173
+ <div class="preview-container border rounded-lg p-4 bg-gray-50 max-h-72 overflow-auto relative">
174
+ <img id="image-preview" class="max-w-full h-auto hidden rounded block mx-auto" alt="Aperçu Image">
175
+ <pre id="text-preview" class="text-sm text-gray-700 whitespace-pre-wrap hidden bg-white p-3 rounded shadow-inner"></pre>
176
+ <p id="file-info" class="text-xs text-gray-500 mt-2 text-center"></p>
177
+ <button id="remove-file-button" class="absolute top-2 right-2 bg-red-100 text-red-600 hover:bg-red-200 rounded-full p-1 text-xs hidden" title="Retirer le fichier">
178
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
179
+ <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
180
+ </svg>
181
  </button>
182
  </div>
183
  </div>
184
 
185
+ <!-- Submit Button -->
186
+ <div class="mt-6 text-center">
187
+ <button id="submit-button"
188
+ disabled
189
+ class="bg-indigo-600 text-white font-medium py-2.5 px-6 rounded-lg shadow hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition duration-150 ease-in-out disabled:opacity-50 disabled:cursor-not-allowed disabled:bg-indigo-300">
190
+ <span id="submit-button-text">3. Lancer l'analyse</span>
191
+ <span id="submit-button-spinner" class="hidden">
192
+ <svg class="animate-spin inline-block -ml-1 mr-2 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
193
+ <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
194
+ <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
195
+ </svg>
196
+ Analyse en cours...
197
  </span>
198
  </button>
199
  </div>
200
 
201
  <!-- Analysis Results -->
202
+ <div id="results" class="mt-10 hidden slide-up">
203
+ <h3 class="text-lg font-semibold text-gray-900 mb-4 border-b pb-2">Analyse détaillée</h3>
204
+ <div class="bg-gray-50 rounded-lg p-4 md:p-6 shadow-inner overflow-x-auto border border-gray-200">
205
+ <!-- Applying prose styles here -->
206
  <div id="analysis-content" class="prose prose-sm sm:prose-base max-w-none prose-indigo">
207
+ <p class="text-gray-500">L'analyse apparaîtra ici...</p>
208
  </div>
209
  </div>
210
  <div class="mt-4 text-right">
211
+ <button id="copy-analysis-button" class="text-sm bg-gray-200 hover:bg-gray-300 text-gray-700 font-medium py-1.5 px-3 rounded-md transition duration-150 ease-in-out">
212
+ Copier l'analyse
213
  </button>
214
  </div>
215
  </div>
216
+ </div> <!-- End main content block -->
217
 
218
+ <footer class="text-center mt-12 text-gray-500 text-sm fade-in">
219
+ <p>© 2025 Mariam Espagnol - Outil d'analyse</p>
 
 
 
220
  </footer>
221
 
222
+ </div> <!-- End max-width container -->
 
223
 
224
  <script>
225
  document.addEventListener('DOMContentLoaded', function() {
 
226
  const uploadZone = document.getElementById('upload-zone');
227
  const fileInput = document.getElementById('file-upload');
228
  const preview = document.getElementById('preview');
 
238
  const copyAnalysisButton = document.getElementById('copy-analysis-button');
239
  const fileTypeRadios = document.querySelectorAll('.file-type-radio');
240
  const fileTypesInfo = document.getElementById('file-types-info');
 
241
 
242
  let selectedFile = null;
243
 
244
+ // Configure marked with Prism check
245
+ marked.setOptions({
246
+ breaks: true,
247
+ gfm: true,
248
+ headerIds: false,
249
+ mangle: false,
250
  highlight: function(code, lang) {
251
+ // ** Check if Prism and the language are loaded **
252
  if (typeof Prism !== 'undefined' && Prism.languages[lang]) {
253
+ try {
254
+ return Prism.highlight(code, Prism.languages[lang], lang);
255
+ } catch (error) {
256
+ console.warn(`Prism highlighting failed for language ${lang}:`, error)
257
+ return code; // Return unhighlighted on error
258
+ }
259
  }
260
+ // ** Fallback if Prism or language not available **
261
  return code;
262
  }
263
  });
264
 
265
+ // --- Helper Functions ---
266
+ function showLoading(isLoading) {
267
+ if (isLoading) {
268
+ submitButtonText.classList.add('hidden');
269
+ submitButtonSpinner.classList.remove('hidden');
270
+ submitButton.disabled = true;
271
+ } else {
272
+ submitButtonText.classList.remove('hidden');
273
+ submitButtonSpinner.classList.add('hidden');
274
+ submitButton.disabled = (selectedFile === null);
275
+ }
276
  }
277
+
278
  function resetUI() {
279
+ selectedFile = null;
280
+ fileInput.value = '';
281
+ preview.classList.add('hidden');
282
+ imagePreview.classList.add('hidden');
283
+ textPreview.classList.add('hidden');
284
+ imagePreview.src = '#';
285
+ textPreview.textContent = '';
286
+ fileInfo.textContent = '';
287
  removeFileButton.classList.add('hidden');
288
+ results.classList.add('hidden');
289
+ analysisContent.innerHTML = '<p class="text-gray-500">L\'analyse apparaîtra ici...</p>';
290
+ submitButton.disabled = true;
291
+ showLoading(false);
292
+ updateAcceptAttribute();
293
  }
294
+
295
+ function updateAcceptAttribute() {
296
  const selectedType = document.querySelector('input[name="fileType"]:checked').value;
297
+ if (selectedType === 'image') {
298
+ fileInput.accept = "image/png, image/jpeg, image/gif, image/webp";
299
+ fileTypesInfo.textContent = "Images (PNG, JPG, GIF, WEBP) - Max 16MB";
300
+ } else {
301
+ fileInput.accept = "text/plain, application/pdf, .txt";
302
+ fileTypesInfo.textContent = "Textes (TXT, PDF lisible) - Max 16MB";
303
+ }
304
  if (selectedFile) {
305
+ const currentFileTypeMatchesSelection =
306
+ (selectedType === 'image' && selectedFile.type.startsWith('image/')) ||
307
+ (selectedType === 'text' && (selectedFile.type === 'text/plain' || selectedFile.type === 'application/pdf' || selectedFile.name.endsWith('.txt')));
308
+
309
  if(!currentFileTypeMatchesSelection) {
310
+ resetUI();
311
+ // Use SweetAlert for this message too
312
+ Swal.fire({
313
+ icon: 'warning',
314
+ title: 'Type de fichier changé',
315
+ text: 'Le type de document a été modifié. Veuillez resélectionner votre fichier.',
316
+ });
317
  }
318
  }
319
  }
320
 
321
+
322
  // --- Event Listeners ---
323
+ fileTypeRadios.forEach(radio => {
324
+ radio.addEventListener('change', updateAcceptAttribute);
325
+ });
326
  uploadZone.addEventListener('click', () => fileInput.click());
327
+ uploadZone.addEventListener('dragover', (e) => {
328
+ e.preventDefault();
329
+ uploadZone.classList.add('dragover');
330
+ });
331
+ uploadZone.addEventListener('dragleave', () => {
332
+ uploadZone.classList.remove('dragover');
333
+ });
334
+ uploadZone.addEventListener('drop', (e) => {
335
+ e.preventDefault();
336
+ uploadZone.classList.remove('dragover');
337
+ if (e.dataTransfer.files.length) {
338
+ handleFileSelection(e.dataTransfer.files[0]);
339
+ }
340
+ });
341
+ fileInput.addEventListener('change', (e) => {
342
+ if (e.target.files.length) {
343
+ handleFileSelection(e.target.files[0]);
344
+ }
345
+ });
346
  removeFileButton.addEventListener('click', resetUI);
347
  submitButton.addEventListener('click', handleSubmit);
348
  copyAnalysisButton.addEventListener('click', copyAnalysisToClipboard);
349
 
350
+
351
+ // --- Core Logic Functions ---
352
+
353
  function handleFileSelection(file) {
354
+ const fileType = document.querySelector('input[name="fileType"]:checked').value;
355
  const maxFileSize = 16 * 1024 * 1024;
356
+
357
+ if (file.size > maxFileSize) {
358
+ Swal.fire({ // Use SweetAlert
359
+ icon: 'error',
360
+ title: 'Fichier trop volumineux',
361
+ text: `La taille maximale autorisée est de 16 Mo. Votre fichier fait ${(file.size / 1024 / 1024).toFixed(1)} Mo.`,
362
+ });
363
+ resetUI();
364
+ return;
365
+ }
366
+
367
+ const allowedImageTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
368
+ const allowedTextTypes = ['text/plain', 'application/pdf'];
369
+
370
+ if (fileType === 'image' && !allowedImageTypes.includes(file.type)) {
371
+ const isImageTypeByName = /\.(jpe?g|png|gif|webp)$/i.test(file.name);
372
+ if (!isImageTypeByName) {
373
+ Swal.fire({ // Use SweetAlert
374
+ icon: 'error',
375
+ title: 'Type de fichier invalide',
376
+ text: 'Veuillez sélectionner une image (PNG, JPG, GIF, WEBP).'
377
+ });
378
+ resetUI();
379
+ return;
380
+ }
381
+ } else if (fileType === 'text' && !allowedTextTypes.includes(file.type)) {
382
+ const isTextTypeByName = /\.txt$/i.test(file.name);
383
+ if (!isTextTypeByName && file.type !== 'application/pdf') {
384
+ Swal.fire({ // Use SweetAlert
385
+ icon: 'error',
386
+ title: 'Type de fichier invalide',
387
+ text: 'Veuillez sélectionner un fichier texte (TXT) ou PDF.'
388
+ });
389
+ resetUI();
390
+ return;
391
+ }
392
+ }
393
+
394
+ // If validation passes:
395
  selectedFile = file;
396
+ preview.classList.remove('hidden');
397
+ preview.classList.add('fade-in');
398
+ results.classList.add('hidden');
399
+ analysisContent.innerHTML = '<p class="text-gray-500">L\'analyse apparaîtra ici...</p>';
400
  fileInfo.textContent = `${file.name} (${(file.size / 1024).toFixed(1)} Ko)`;
401
  removeFileButton.classList.remove('hidden');
402
+
403
  if (fileType === 'image') {
404
+ imagePreview.classList.remove('hidden');
405
+ textPreview.classList.add('hidden');
406
+ const reader = new FileReader();
407
+ reader.onload = (e) => imagePreview.src = e.target.result;
408
+ reader.readAsDataURL(file);
409
  } else {
410
+ imagePreview.classList.add('hidden');
411
+ textPreview.classList.remove('hidden');
412
+ if (file.type === 'application/pdf') {
413
+ textPreview.textContent = "Aperçu non disponible pour les fichiers PDF. Le contenu sera analysé.";
414
+ } else {
415
+ const reader = new FileReader();
416
+ reader.onload = (e) => textPreview.textContent = e.target.result;
417
+ reader.readAsText(file);
418
+ }
419
  }
420
  submitButton.disabled = false;
421
  }
422
 
423
  function handleSubmit() {
424
+ if (!selectedFile) {
425
+ Swal.fire('Aucun fichier', 'Veuillez sélectionner un fichier avant de lancer l\'analyse.', 'warning');
426
+ return;
427
+ }
428
+
429
  const fileType = document.querySelector('input[name="fileType"]:checked').value;
430
+ const formData = new FormData();
431
+ formData.append('file', selectedFile);
432
+ formData.append('fileType', fileType);
433
+
434
+ showLoading(true);
435
+ results.classList.add('hidden');
436
+
437
+ fetch('/upload', {
438
+ method: 'POST',
439
+ body: formData
440
+ })
441
  .then(response => {
442
+ if (!response.ok) {
443
+ return response.json().then(errData => {
444
+ throw new Error(errData.error || `Erreur HTTP: ${response.status}`);
445
+ }).catch(() => {
446
+ throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`);
447
+ });
448
+ }
449
  return response.json();
450
  })
451
  .then(data => {
452
+ showLoading(false);
453
  if (data.success && data.analysis) {
454
+ results.classList.remove('hidden');
455
+ results.classList.add('slide-up');
456
  analysisContent.innerHTML = marked.parse(data.analysis);
457
+
458
+ // ** Check if Prism is loaded before highlighting **
459
+ if (typeof Prism !== 'undefined') {
460
+ // Use Prism's autoloader or highlightAllUnder
461
+ // Prism.highlightAllUnder(analysisContent); // Might work with autoloader
462
+ // Or manually trigger highlighting on specific elements if autoloader fails:
463
+ analysisContent.querySelectorAll('pre code').forEach((block) => {
464
+ Prism.highlightElement(block);
465
+ });
466
+ } else {
467
+ console.warn("Prism n'est pas chargé, impossible de colorer la syntaxe.");
468
+ }
469
+
470
  results.scrollIntoView({ behavior: 'smooth', block: 'start' });
471
+ } else {
472
+ throw new Error(data.error || "L'analyse n'a pas pu être générée.");
473
+ }
474
  })
475
  .catch(error => {
476
+ showLoading(false);
477
+ // Use SweetAlert for error display
478
+ Swal.fire({
479
+ icon: 'error',
480
+ title: 'Erreur lors de l\'analyse',
481
+ text: error.message || 'Une erreur inconnue est survenue.',
482
+ });
483
+ // Optionally log detailed error
484
+ console.error('Error during analysis:', error);
485
+ submitButton.disabled = false; // Re-enable on error
486
  });
487
  }
488
 
489
+ function copyAnalysisToClipboard() {
490
+ const analysisHtml = analysisContent.innerHTML;
491
+ if (!analysisHtml || analysisHtml.includes('L\'analyse apparaîtra ici...')) {
492
+ Swal.fire('Rien à copier', 'Aucune analyse n\'a été générée pour le moment.', 'info');
493
+ return;
494
+ }
495
+
496
+ const tempDiv = document.createElement('div');
497
+ tempDiv.innerHTML = analysisHtml;
498
+ let textToCopy = tempDiv.textContent || tempDiv.innerText || "";
499
+
500
+ // Basic conversion for better text format
501
+ textToCopy = analysisHtml
502
+ .replace(/<br\s*\/?>/gi, '\n')
503
+ .replace(/<\/p>/gi, '\n')
504
+ .replace(/<\/li>/gi, '\n')
505
+ .replace(/<\/(h[1-6])>/gi, '\n\n')
506
+ .replace(/<pre.*?><code.*?>([\s\S]*?)<\/code><\/pre>/gi, '\n```\n$1\n```\n') // Attempt to format code blocks
507
+ .replace(/<[^>]+>/g, '') // Remove remaining tags
508
+ .replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&') // Decode entities
509
+ .trim();
510
+
511
+ navigator.clipboard.writeText(textToCopy)
512
+ .then(() => {
513
+ // Use SweetAlert for success
514
+ Swal.fire({
515
+ icon: 'success',
516
+ title: 'Copié !',
517
+ text: 'L\'analyse a été copiée dans le presse-papiers.',
518
+ timer: 1500, // Auto-close after 1.5 seconds
519
+ showConfirmButton: false // Hide the confirmation button
520
+ });
521
+ })
522
+ .catch(err => {
523
+ console.error('Erreur de copie: ', err);
524
+ // Use SweetAlert for error
525
+ Swal.fire({
526
+ icon: 'error',
527
+ title: 'Erreur de copie',
528
+ text: 'Impossible de copier l\'analyse automatiquement. Vous pouvez essayer de la sélectionner manuellement.',
529
+ });
530
+ });
531
  }
532
 
533
+
534
  // --- Initial Setup ---
535
  updateAcceptAttribute();
536
  resetUI();
537
+
538
  }); // End DOMContentLoaded
539
  </script>
540
  </body>