Spaces:
Running
Running
Update templates/maj.html
Browse files- templates/maj.html +669 -588
templates/maj.html
CHANGED
@@ -1,614 +1,695 @@
|
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="fr">
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
|
10 |
-
<style>
|
11 |
-
:root {
|
12 |
-
--primary-color: #4a6fa5;
|
13 |
-
--secondary-color: #166088;
|
14 |
-
--accent-color: #4fc3f7;
|
15 |
-
--background-color: #f8f9fa;
|
16 |
-
--text-color: #333;
|
17 |
-
--box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
18 |
-
--code-bg: #282c34; /* atom-one-dark background */
|
19 |
-
--code-text: #abb2bf; /* atom-one-dark default text */
|
20 |
-
--output-bg: #f1f8f9;
|
21 |
-
}
|
22 |
-
|
23 |
-
body {
|
24 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
25 |
-
line-height: 1.6;
|
26 |
-
margin: 0;
|
27 |
-
padding: 0;
|
28 |
-
background-color: var(--background-color);
|
29 |
-
color: var(--text-color);
|
30 |
-
}
|
31 |
-
|
32 |
-
.container {
|
33 |
-
max-width: 1000px;
|
34 |
-
margin: 0 auto;
|
35 |
-
padding: 20px;
|
36 |
-
}
|
37 |
-
|
38 |
-
header {
|
39 |
-
text-align: center;
|
40 |
-
padding: 20px 0;
|
41 |
-
margin-bottom: 30px;
|
42 |
-
}
|
43 |
-
|
44 |
-
.logo {
|
45 |
-
font-size: 2.5rem;
|
46 |
-
font-weight: bold;
|
47 |
-
color: var(--primary-color);
|
48 |
-
margin-bottom: 10px;
|
49 |
-
}
|
50 |
-
|
51 |
-
.subtitle {
|
52 |
-
font-size: 1.2rem;
|
53 |
-
color: var(--secondary-color);
|
54 |
-
margin-bottom: 20px;
|
55 |
-
}
|
56 |
-
|
57 |
-
.content-box {
|
58 |
-
background-color: white;
|
59 |
-
border-radius: 10px;
|
60 |
-
box-shadow: var(--box-shadow);
|
61 |
-
padding: 30px;
|
62 |
-
margin-bottom: 30px;
|
63 |
-
/* Removed text-align: center; allowing content to align left */
|
64 |
-
}
|
65 |
-
|
66 |
-
h1, h2, h3 {
|
67 |
-
color: var(--primary-color);
|
68 |
-
margin-top: 0;
|
69 |
-
text-align: center; /* Center headings specifically */
|
70 |
-
}
|
71 |
-
h2 {
|
72 |
-
margin-top: 1.5em; /* Add space above h2 */
|
73 |
-
}
|
74 |
-
|
75 |
-
.feature-list {
|
76 |
-
list-style-type: none;
|
77 |
-
padding: 0;
|
78 |
-
margin: 30px auto; /* Center list container */
|
79 |
-
text-align: left;
|
80 |
-
max-width: 500px; /* Constrain width for better readability */
|
81 |
-
}
|
82 |
-
|
83 |
-
.feature-list li {
|
84 |
-
padding: 10px 0;
|
85 |
-
margin-bottom: 10px;
|
86 |
-
display: flex;
|
87 |
-
align-items: center;
|
88 |
-
}
|
89 |
-
|
90 |
-
.feature-list i {
|
91 |
-
color: var(--accent-color);
|
92 |
-
margin-right: 10px;
|
93 |
-
font-size: 1.2rem;
|
94 |
-
width: 20px; /* Ensure consistent icon alignment */
|
95 |
-
text-align: center;
|
96 |
-
}
|
97 |
-
.feature-list i.fa-times-circle {
|
98 |
-
color: #aaa; /* Muted color for disabled features */
|
99 |
-
}
|
100 |
-
|
101 |
-
.cta-button {
|
102 |
-
display: inline-block;
|
103 |
-
background-color: var(--primary-color);
|
104 |
-
color: white;
|
105 |
-
padding: 12px 25px;
|
106 |
-
border-radius: 5px;
|
107 |
-
text-decoration: none;
|
108 |
-
font-weight: bold;
|
109 |
-
transition: all 0.3s ease;
|
110 |
-
margin: 20px 10px;
|
111 |
-
border: none;
|
112 |
-
cursor: pointer;
|
113 |
-
font-size: 1rem;
|
114 |
-
}
|
115 |
-
|
116 |
-
.cta-button:hover {
|
117 |
-
background-color: var(--secondary-color);
|
118 |
-
transform: translateY(-2px);
|
119 |
-
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
120 |
-
}
|
121 |
-
.cta-button:disabled {
|
122 |
-
background-color: #ccc;
|
123 |
-
cursor: not-allowed;
|
124 |
-
transform: none;
|
125 |
-
box-shadow: none;
|
126 |
-
}
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
padding-top: 20px;
|
131 |
-
border-top: 1px solid #ddd;
|
132 |
-
text-align: center;
|
133 |
-
}
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
color: #666;
|
139 |
-
font-size: 0.9rem;
|
140 |
-
}
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
text-align: left; /* Ensure solution text aligns left */
|
145 |
-
}
|
146 |
-
|
147 |
-
#solution {
|
148 |
-
background: #fff;
|
149 |
-
padding: 20px;
|
150 |
-
border-radius: 8px;
|
151 |
-
border: 1px solid #eee; /* Add a subtle border */
|
152 |
-
margin-top: 15px;
|
153 |
-
line-height: 1.8;
|
154 |
-
font-size: 16px;
|
155 |
-
overflow-wrap: break-word; /* Wrap long lines */
|
156 |
-
white-space: pre-wrap; /* Preserve whitespace and newlines from response */
|
157 |
-
}
|
158 |
-
|
159 |
-
/* Styling for Markdown code blocks generated by Python */
|
160 |
-
#solution pre {
|
161 |
-
background-color: var(--code-bg);
|
162 |
-
color: var(--code-text);
|
163 |
-
padding: 15px;
|
164 |
-
border-radius: 5px;
|
165 |
-
overflow-x: auto;
|
166 |
-
margin: 15px 0; /* Add spacing around code blocks */
|
167 |
-
box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
|
168 |
-
}
|
169 |
-
|
170 |
-
#solution pre code {
|
171 |
-
font-family: 'Courier New', Courier, monospace;
|
172 |
-
font-size: 14px;
|
173 |
-
line-height: 1.5;
|
174 |
-
white-space: pre; /* Ensure pre formatting is respected within code tag */
|
175 |
-
background: none; /* Remove double background */
|
176 |
-
padding: 0; /* Remove double padding */
|
177 |
-
}
|
178 |
-
|
179 |
-
/* Styling for the execution result block (if Python wraps it) */
|
180 |
-
#solution .output-section { /* Use if Python wraps result in <div class="output-section"> */
|
181 |
-
background-color: var(--output-bg);
|
182 |
-
padding: 15px;
|
183 |
-
border-radius: 5px;
|
184 |
-
border: 1px solid #ddd;
|
185 |
-
color: #333;
|
186 |
-
font-family: 'Courier New', monospace;
|
187 |
-
font-size: 14px;
|
188 |
-
white-space: pre-wrap;
|
189 |
-
overflow-x: auto;
|
190 |
-
margin: 15px 0;
|
191 |
-
}
|
192 |
-
/* Styling for result block if using Markdown ``` only */
|
193 |
-
#solution pre code:not(.language-python) {
|
194 |
-
/* Style non-Python code blocks (likely execution results) differently */
|
195 |
-
background-color: var(--output-bg);
|
196 |
-
color: #333;
|
197 |
-
display: block; /* Make it block level for padding */
|
198 |
-
padding: 10px;
|
199 |
-
border-radius: 4px;
|
200 |
-
border: 1px solid #eee;
|
201 |
-
}
|
202 |
-
/* Identify result block by preceding text */
|
203 |
-
#solution strong:contains("Résultat d'exécution:") + pre {
|
204 |
-
/* Style the <pre> immediately following the specific strong tag */
|
205 |
-
border: 1px dashed #ccc;
|
206 |
-
background-color: #fdfdfd;
|
207 |
-
}
|
208 |
-
#solution strong:contains("Résultat d'exécution:") + pre code {
|
209 |
-
/* Style the <code> inside that specific <pre> */
|
210 |
-
background-color: transparent; /* No extra background */
|
211 |
-
color: #222;
|
212 |
-
}
|
213 |
-
|
214 |
-
|
215 |
-
/* Removed step-section styling as structure is now simpler */
|
216 |
-
|
217 |
-
/* Removed indicator styles (thinking, executing etc.) */
|
218 |
-
.loading-indicator {
|
219 |
-
display: flex;
|
220 |
-
align-items: center;
|
221 |
-
justify-content: center; /* Center content */
|
222 |
-
padding: 15px;
|
223 |
-
margin: 20px 0;
|
224 |
-
border-radius: 8px;
|
225 |
-
font-size: 1rem;
|
226 |
-
background-color: #e3f2fd;
|
227 |
-
color: #1565c0;
|
228 |
-
border: 1px solid #bbdefb;
|
229 |
-
}
|
230 |
-
.loading-indicator i {
|
231 |
-
margin-right: 10px;
|
232 |
-
animation: spin 1.5s linear infinite;
|
233 |
-
}
|
234 |
-
@keyframes spin {
|
235 |
-
0% { transform: rotate(0deg); }
|
236 |
-
100% { transform: rotate(360deg); }
|
237 |
-
}
|
238 |
-
|
239 |
-
|
240 |
-
/* MathJax specific styles for better overflow handling */
|
241 |
-
.MathJax, mjx-container {
|
242 |
-
overflow-x: auto !important;
|
243 |
-
overflow-y: hidden !important;
|
244 |
-
max-width: 100% !important;
|
245 |
-
min-width: 0 !important; /* Prevent minimum width issues */
|
246 |
-
padding: 5px 0; /* Add a bit of vertical padding */
|
247 |
-
display: block !important; /* Ensure it behaves like a block */
|
248 |
-
text-align: left !important; /* Align LaTeX left by default */
|
249 |
-
}
|
250 |
-
mjx-container[display="true"] {
|
251 |
-
display: block !important;
|
252 |
-
margin: 1em 0 !important; /* Spacing for display math */
|
253 |
-
text-align: center !important; /* Center display math */
|
254 |
-
}
|
255 |
-
|
256 |
-
@media (max-width: 768px) {
|
257 |
-
.container {
|
258 |
-
padding: 15px;
|
259 |
-
}
|
260 |
-
.content-box {
|
261 |
-
padding: 20px;
|
262 |
-
}
|
263 |
-
#solution pre {
|
264 |
-
padding: 10px;
|
265 |
-
}
|
266 |
-
#solution pre code {
|
267 |
-
font-size: 13px;
|
268 |
-
}
|
269 |
-
}
|
270 |
-
.upload-section {
|
271 |
-
text-align: center; /* Center upload elements */
|
272 |
-
}
|
273 |
-
#imagePreview {
|
274 |
-
display: none;
|
275 |
-
margin: 20px auto;
|
276 |
-
max-width: 90%; /* Responsive max width */
|
277 |
-
max-height: 400px; /* Limit preview height */
|
278 |
-
}
|
279 |
-
#preview {
|
280 |
-
max-width: 100%;
|
281 |
-
max-height: 400px; /* Match container height */
|
282 |
-
height: auto; /* Maintain aspect ratio */
|
283 |
-
width: auto; /* Maintain aspect ratio */
|
284 |
-
border-radius: 8px;
|
285 |
-
box-shadow: var(--box-shadow);
|
286 |
-
border: 1px solid #ddd;
|
287 |
-
}
|
288 |
-
#uploadStatus {
|
289 |
-
margin-top: 15px;
|
290 |
-
font-size: 0.9em;
|
291 |
-
color: #555;
|
292 |
-
}
|
293 |
-
.error-message {
|
294 |
-
color: red;
|
295 |
-
background-color: #ffeeee;
|
296 |
-
border: 1px solid red;
|
297 |
-
padding: 10px;
|
298 |
-
margin: 15px 0;
|
299 |
-
border-radius: 5px;
|
300 |
-
text-align: left;
|
301 |
-
}
|
302 |
-
</style>
|
303 |
-
</head>
|
304 |
-
<body>
|
305 |
-
<div class="container">
|
306 |
-
<header>
|
307 |
-
<div class="logo">Math Solver</div>
|
308 |
-
<div class="subtitle">La solution intelligente pour vos problèmes mathématiques</div>
|
309 |
-
</header>
|
310 |
-
|
311 |
-
<div class="content-box">
|
312 |
-
<h1>Version Gratuite</h1>
|
313 |
-
<p style="text-align: center;">Vous utilisez actuellement la version gratuite de Math Solver.</p> <!-- Centered paragraph -->
|
314 |
-
|
315 |
-
<div class="upload-section">
|
316 |
-
<h2>Soumettez votre problème</h2>
|
317 |
-
<form id="imageForm" enctype="multipart/form-data">
|
318 |
-
<input type="file" id="imageInput" name="image" accept="image/*" style="display: none;">
|
319 |
-
<button type="button" id="uploadButton" class="cta-button">
|
320 |
-
<i class="fas fa-upload"></i> Télécharger une image
|
321 |
-
</button>
|
322 |
-
</form>
|
323 |
-
<p id="uploadStatus"></p>
|
324 |
-
<div id="imagePreview">
|
325 |
-
<img id="preview" alt="Aperçu de l'image">
|
326 |
-
</div>
|
327 |
-
<button id="solveButton" class="cta-button" style="display: none; background-color: var(--secondary-color);" disabled>
|
328 |
-
<i class="fas fa-calculator"></i> Résoudre ce problème
|
329 |
-
</button>
|
330 |
-
</div>
|
331 |
-
|
332 |
-
<!-- Solution Output Area -->
|
333 |
-
<div id="solutionOutput" style="display: none;"> <!-- Keep hidden initially -->
|
334 |
-
<hr style="margin: 30px 0;"> <!-- Separator -->
|
335 |
-
<h3>Solution :</h3>
|
336 |
-
<div id="loadingIndicator" class="loading-indicator" style="display: none;">
|
337 |
-
<i class="fas fa-spinner"></i> <!-- Changed to spinner -->
|
338 |
-
<span>Résolution en cours...</span>
|
339 |
-
</div>
|
340 |
-
<div id="solution"></div> <!-- Solution content will appear here -->
|
341 |
-
<div id="errorContainer" class="error-message" style="display: none;"></div> <!-- Error messages -->
|
342 |
-
</div>
|
343 |
-
|
344 |
-
|
345 |
-
<div class="feature-list">
|
346 |
-
<h2>Fonctionnalités :</h2>
|
347 |
-
<ul> <!-- Removed ul class -->
|
348 |
-
<li><i class="fas fa-check-circle"></i> Résolution de problèmes mathématiques</li>
|
349 |
-
<li><i class="fas fa-check-circle"></i> Explication des étapes (si fournies par l'IA)</li>
|
350 |
-
<li><i class="fas fa-check-circle"></i> Utilisation de LaTeX pour les formules</li>
|
351 |
-
<li><i class="fas fa-check-circle"></i> Exécution de code Python pour calculs</li>
|
352 |
-
<li><i class="fas fa-times-circle"></i> <span style="color: #999;">Résolutions illimitées (version Pro)</span></li>
|
353 |
-
<li><i class="fas fa-times-circle"></i> <span style="color: #999;">Support prioritaire (version Pro)</span></li>
|
354 |
-
</ul>
|
355 |
-
</div>
|
356 |
-
|
357 |
-
<div class="upgrade-section">
|
358 |
-
<h2>Besoin de plus ?</h2>
|
359 |
-
<p>Passez à la version Pro pour des fonctionnalités avancées et des résolutions illimitées.</p>
|
360 |
-
<a href="/" class="cta-button">Découvrir la version Pro</a> <!-- Link to Pro version page -->
|
361 |
-
</div>
|
362 |
-
</div>
|
363 |
-
|
364 |
-
<footer>
|
365 |
-
<p>© 2025 Math Solver. Tous droits réservés.</p>
|
366 |
-
</footer>
|
367 |
-
</div>
|
368 |
-
|
369 |
-
<!-- Use latest highlight.js -->
|
370 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
371 |
-
<!-- Add languages you expect, python is essential -->
|
372 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/python.min.js"></script>
|
373 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/bash.min.js"></script> <!-- For shell output maybe -->
|
374 |
-
|
375 |
-
<!-- Use Marked.js for Markdown rendering -->
|
376 |
-
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
377 |
-
|
378 |
-
<!-- MathJax Configuration -->
|
379 |
-
<script>
|
380 |
window.MathJax = {
|
381 |
tex: {
|
382 |
-
inlineMath: [['$', '$']
|
383 |
-
displayMath: [['$$', '$$']
|
384 |
processEscapes: true,
|
385 |
-
|
386 |
-
packages: {'[+]': ['ams', 'noerrors', 'physics', 'cancel', 'color', 'mhchem', 'mathtools']} // Load common packages
|
387 |
},
|
388 |
options: {
|
389 |
-
enableMenu: false,
|
390 |
-
|
391 |
-
processHtmlClass: 'tex2jax_process', // Class to process (can add to #solution if needed)
|
392 |
-
skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'] // Skip these tags
|
393 |
},
|
394 |
startup: {
|
395 |
-
|
396 |
-
ready: () => {
|
397 |
-
console.log('MathJax is ready');
|
398 |
-
MathJax.startup.defaultReady();
|
399 |
-
// You could potentially trigger an initial typeset if needed
|
400 |
-
// MathJax.startup.promise.then(() => { MathJax.typesetPromise(); });
|
401 |
-
}
|
402 |
-
},
|
403 |
-
loader: {
|
404 |
-
load: ['[tex]/ams', '[tex]/noerrors', '[tex]/physics', '[tex]/cancel', '[tex]/color', '[tex]/mhchem', '[tex]/mathtools'] // Ensure packages are loaded
|
405 |
-
},
|
406 |
-
svg: {
|
407 |
-
fontCache: 'global' // Cache fonts for better performance
|
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 |
-
imagePreview.style.display = 'block';
|
462 |
-
solveButton.style.display = 'inline-block';
|
463 |
-
solveButton.disabled = false; // Enable solve button
|
464 |
-
uploadStatus.textContent = `Image sélectionnée : ${file.name}`;
|
465 |
-
uploadStatus.style.color = '#555'; // Reset color
|
466 |
-
// Clear previous solution/error
|
467 |
-
solutionOutput.style.display = 'none';
|
468 |
-
solutionDiv.innerHTML = '';
|
469 |
-
errorContainer.style.display = 'none';
|
470 |
-
errorContainer.textContent = '';
|
471 |
|
|
|
|
|
|
|
|
|
|
|
472 |
}
|
473 |
-
reader.onerror = function() {
|
474 |
-
uploadStatus.textContent = 'Erreur : Impossible de lire le fichier image.';
|
475 |
-
uploadStatus.style.color = 'red';
|
476 |
-
imagePreview.style.display = 'none';
|
477 |
-
solveButton.style.display = 'none';
|
478 |
-
solveButton.disabled = true;
|
479 |
-
}
|
480 |
-
reader.readAsDataURL(file);
|
481 |
-
} else {
|
482 |
-
// No file selected or selection cancelled
|
483 |
-
uploadStatus.textContent = '';
|
484 |
-
imagePreview.style.display = 'none';
|
485 |
-
solveButton.style.display = 'none';
|
486 |
-
solveButton.disabled = true;
|
487 |
-
}
|
488 |
-
});
|
489 |
-
|
490 |
-
// Handle form submission (clicking the solve button)
|
491 |
-
solveButton.addEventListener('click', function() {
|
492 |
-
const file = imageInput.files[0];
|
493 |
-
if (!file) {
|
494 |
-
showError('Veuillez d\'abord sélectionner une image.');
|
495 |
-
return;
|
496 |
}
|
497 |
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
// Try to parse JSON error body from server
|
516 |
-
return response.json().then(errData => {
|
517 |
-
// Throw an error with the message from server JSON
|
518 |
-
throw new Error(errData.error || `Erreur HTTP ${response.status}`);
|
519 |
-
}).catch(() => {
|
520 |
-
// If JSON parsing fails, throw generic HTTP error
|
521 |
-
throw new Error(`Erreur HTTP ${response.status}: ${response.statusText}`);
|
522 |
-
});
|
523 |
-
}
|
524 |
-
return response.json(); // Parse successful response as JSON
|
525 |
-
})
|
526 |
-
.then(data => {
|
527 |
-
loadingIndicator.style.display = 'none'; // Hide loading indicator
|
528 |
-
|
529 |
-
if (data.error) {
|
530 |
-
// Handle errors returned in the JSON payload
|
531 |
-
showError(data.error);
|
532 |
-
} else if (data.solution) {
|
533 |
-
// Use Marked.js to render the Markdown solution from the server
|
534 |
-
// This handles ```python blocks, standard markdown, etc.
|
535 |
-
// Ensure Marked converts ```python to <pre><code class="language-python">
|
536 |
-
marked.setOptions({
|
537 |
-
highlight: function(code, lang) {
|
538 |
-
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
539 |
-
return hljs.highlight(code, { language, ignoreIllegals: true }).value;
|
540 |
-
},
|
541 |
-
langPrefix: 'language-', // standard prefix for hljs
|
542 |
-
pedantic: false,
|
543 |
-
gfm: true, // Enable GitHub Flavored Markdown
|
544 |
-
breaks: true, // Convert single newlines in paragraphs into <br>
|
545 |
-
smartLists: true,
|
546 |
-
smartypants: false, // Avoid changing quotes/dashes
|
547 |
-
xhtml: false
|
548 |
-
});
|
549 |
-
|
550 |
-
solutionDiv.innerHTML = marked.parse(data.solution);
|
551 |
-
|
552 |
-
// --- MathJax Typesetting ---
|
553 |
-
// Check if MathJax is loaded and ready before typesetting
|
554 |
-
if (window.MathJax && MathJax.startup) {
|
555 |
-
MathJax.startup.promise = MathJax.startup.promise.then(() => {
|
556 |
-
console.log("Typesetting MathJax content...");
|
557 |
-
// Typeset the entire solutionDiv AFTER rendering Markdown
|
558 |
-
return MathJax.typesetPromise([solutionDiv]);
|
559 |
-
}).catch((err) => {
|
560 |
-
console.error('MathJax typesetting failed:', err);
|
561 |
-
showError('Erreur lors du rendu des formules mathématiques.');
|
562 |
-
});
|
563 |
} else {
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
}
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
599 |
});
|
|
|
600 |
});
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
</body>
|
614 |
</html>
|
|
|
1 |
+
|
2 |
<!DOCTYPE html>
|
3 |
<html lang="fr">
|
4 |
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Mariam M-1 | Solution Mathématique</title>
|
8 |
+
<!-- Tailwind CSS -->
|
9 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
<!-- SweetAlert2 -->
|
12 |
+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
<!-- Highlight.js pour la coloration syntaxique -->
|
15 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github.min.css">
|
16 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
|
|
|
|
|
|
|
17 |
|
18 |
+
<!-- Configuration de MathJax -->
|
19 |
+
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
window.MathJax = {
|
21 |
tex: {
|
22 |
+
inlineMath: [['$', '$']],
|
23 |
+
displayMath: [['$$', '$$']],
|
24 |
processEscapes: true,
|
25 |
+
packages: {'[+]': ['autoload', 'ams']}
|
|
|
26 |
},
|
27 |
options: {
|
28 |
+
enableMenu: false,
|
29 |
+
messageStyle: 'none'
|
|
|
|
|
30 |
},
|
31 |
startup: {
|
32 |
+
pageReady: () => { window.mathJaxReady = true; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
};
|
35 |
+
</script>
|
36 |
+
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
|
37 |
+
<script src="https://cdn.jsdelivr.net/npm/marked@15.0.7/lib/marked.umd.min.js"></script>
|
38 |
+
|
39 |
+
<style>
|
40 |
+
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap');
|
41 |
+
body { font-family: 'Space Grotesk', sans-serif; }
|
42 |
+
|
43 |
+
.uploadArea {
|
44 |
+
background: #f3f4f6;
|
45 |
+
border: 2px dashed #d1d5db;
|
46 |
+
transition: border-color 0.2s ease;
|
47 |
+
}
|
48 |
+
.uploadArea:hover { border-color: #3b82f6; }
|
49 |
+
|
50 |
+
.blue-button { background: #3b82f6; transition: background-color 0.2s ease; }
|
51 |
+
.blue-button:hover { background: #2563eb; }
|
52 |
+
|
53 |
+
.loader {
|
54 |
+
width: 48px;
|
55 |
+
height: 48px;
|
56 |
+
border: 3px solid #3b82f6;
|
57 |
+
border-bottom-color: transparent;
|
58 |
+
border-radius: 50%;
|
59 |
+
display: inline-block;
|
60 |
+
animation: rotation 1s linear infinite;
|
61 |
+
}
|
62 |
+
@keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
63 |
+
|
64 |
+
.thought-box {
|
65 |
+
transition: max-height 0.3s ease-out;
|
66 |
+
max-height: 0;
|
67 |
+
overflow: hidden;
|
68 |
+
}
|
69 |
+
.thought-box.open { max-height: 500px; }
|
70 |
+
|
71 |
+
#thoughtsContent, #answerContent {
|
72 |
+
max-height: 500px;
|
73 |
+
overflow-y: auto;
|
74 |
+
scroll-behavior: smooth;
|
75 |
+
white-space: pre-wrap;
|
76 |
+
}
|
77 |
+
|
78 |
+
.preview-image { max-width: 300px; max-height: 300px; object-fit: contain; }
|
79 |
+
|
80 |
+
.timestamp { color: #3b82f6; font-size: 0.9em; margin-left: 8px; }
|
81 |
+
|
82 |
+
table {
|
83 |
+
border-collapse: collapse;
|
84 |
+
width: 100%;
|
85 |
+
margin-bottom: 1rem;
|
86 |
+
}
|
87 |
+
th, td {
|
88 |
+
border: 1px solid #d1d5db;
|
89 |
+
padding: 0.5rem;
|
90 |
+
text-align: left;
|
91 |
+
}
|
92 |
+
th { background-color: #f3f4f6; font-weight: 600; }
|
93 |
+
.table-responsive { overflow-x: auto; }
|
94 |
+
|
95 |
+
/* Style pour le bouton Sauvegarder afin de le mettre en évidence */
|
96 |
+
#saveButton {
|
97 |
+
background: #3b82f6;
|
98 |
+
color: white;
|
99 |
+
padding: 0.5rem 1rem;
|
100 |
+
border-radius: 0.375rem;
|
101 |
+
transition: background-color 0.2s ease;
|
102 |
+
}
|
103 |
+
#saveButton:hover { background: #2563eb; }
|
104 |
+
|
105 |
+
/* Modal plein écran pour les sauvegardes */
|
106 |
+
#savedModal {
|
107 |
+
display: none;
|
108 |
+
position: fixed;
|
109 |
+
inset: 0;
|
110 |
+
background: rgba(0,0,0,0.5);
|
111 |
+
z-index: 50;
|
112 |
+
}
|
113 |
+
#savedModal.active { display: block; }
|
114 |
+
#savedModalContent {
|
115 |
+
background: #fff;
|
116 |
+
width: 100%;
|
117 |
+
height: 100%;
|
118 |
+
overflow-y: auto;
|
119 |
+
}
|
120 |
+
|
121 |
+
/* Styles spécifiques pour le code et son exécution */
|
122 |
+
pre {
|
123 |
+
background-color: #f8f8f8;
|
124 |
+
border: 1px solid #e2e8f0;
|
125 |
+
border-radius: 0.375rem;
|
126 |
+
padding: 1rem;
|
127 |
+
margin: 1rem 0;
|
128 |
+
overflow-x: auto;
|
129 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
130 |
+
}
|
131 |
+
|
132 |
+
code {
|
133 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
134 |
+
}
|
135 |
+
|
136 |
+
.code-execution-result {
|
137 |
+
background-color: #f0fff4;
|
138 |
+
border-left: 4px solid #48bb78;
|
139 |
+
padding: 1rem;
|
140 |
+
margin: 1rem 0;
|
141 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
142 |
+
white-space: pre-wrap;
|
143 |
+
}
|
144 |
+
|
145 |
+
/* Styles pour les types de contenu spécifiques */
|
146 |
+
.content-text {}
|
147 |
+
.content-code { padding: 0; }
|
148 |
+
.content-result {
|
149 |
+
background-color: #f0fff4;
|
150 |
+
border-left: 4px solid #48bb78;
|
151 |
+
padding: 1rem;
|
152 |
+
margin: 0.5rem 0;
|
153 |
+
}
|
154 |
+
.content-image { margin: 1rem 0; text-align: center; }
|
155 |
+
.content-image img { max-width: 100%; }
|
156 |
+
|
157 |
+
</style>
|
158 |
+
</head>
|
159 |
+
<body class="p-4">
|
160 |
+
<div class="max-w-4xl mx-auto">
|
161 |
+
<header class="p-6 text-center mb-8">
|
162 |
+
<h1 class="text-4xl font-bold text-blue-600">Mariam M-1(avec calculatrice)</h1>
|
163 |
+
<p class="text-gray-600">Solution Mathématique/Physique/Chimie Intelligente, avec intégration d'une calculatrice.</p>
|
164 |
+
<div class="mt-4 flex justify-end">
|
165 |
+
<button id="openSaved" class="blue-button px-4 py-2 text-white rounded">Sauvegardes</button>
|
166 |
+
</div>
|
167 |
+
</header>
|
168 |
+
|
169 |
+
<main id="mainContent">
|
170 |
+
<form id="problemForm" class="space-y-6" novalidate>
|
171 |
+
<!-- Zone de dépôt / sélection d'image -->
|
172 |
+
<div class="uploadArea p-8 text-center relative" aria-label="Zone de dépôt d'image">
|
173 |
+
<input type="file" id="imageInput" name="image" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" aria-label="Choisir une image">
|
174 |
+
<div class="space-y-3">
|
175 |
+
<div class="w-16 h-16 mx-auto border-2 border-blue-400 rounded-full flex items-center justify-center">
|
176 |
+
<svg class="w-8 h-8 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
177 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
178 |
+
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
179 |
+
</svg>
|
180 |
+
</div>
|
181 |
+
<p class="text-gray-700 font-medium">Déposez votre image ici</p>
|
182 |
+
<p class="text-gray-500 text-sm">ou cliquez pour sélectionner</p>
|
183 |
+
</div>
|
184 |
+
</div>
|
185 |
+
<!-- Aperçu de l'image -->
|
186 |
+
<div id="imagePreview" class="hidden text-center">
|
187 |
+
<img id="previewImage" class="preview-image mx-auto" alt="Prévisualisation de l'image">
|
188 |
+
</div>
|
189 |
+
<button type="submit" class="blue-button w-full py-3 text-white font-medium rounded-lg">
|
190 |
+
Résoudre le problème
|
191 |
+
</button>
|
192 |
+
</form>
|
193 |
+
|
194 |
+
<!-- Loader -->
|
195 |
+
<div id="loader" class="hidden mt-8 text-center">
|
196 |
+
<span class="loader"></span>
|
197 |
+
<p class="mt-4 text-gray-600">Analyse en cours...</p>
|
198 |
+
</div>
|
199 |
+
|
200 |
+
<!-- Zone d'affichage de la solution -->
|
201 |
+
<section id="solution" class="hidden mt-8 space-y-6 relative">
|
202 |
+
<div class="border-t pt-4">
|
203 |
+
<button id="thoughtsToggle" type="button" class="w-full flex justify-between items-center p-2">
|
204 |
+
<span class="font-medium text-gray-700">Processus de Réflexion</span>
|
205 |
+
<span id="timestamp" class="timestamp"></span>
|
206 |
+
</button>
|
207 |
+
<div id="thoughtsBox" class="thought-box">
|
208 |
+
<div id="thoughtsContent" class="p-4 text-gray-600"></div>
|
209 |
+
</div>
|
210 |
+
</div>
|
211 |
+
<div class="border-t pt-6">
|
212 |
+
<div class="flex justify-between items-center">
|
213 |
+
<h3 class="text-xl font-bold text-gray-800 mb-4">Solution</h3>
|
214 |
+
<!-- Bouton Sauvegarder mis en évidence -->
|
215 |
+
<button id="saveButton">Sauvegarder</button>
|
216 |
+
</div>
|
217 |
+
<div id="answerContent" class="text-gray-700 table-responsive"></div>
|
218 |
+
</div>
|
219 |
+
</section>
|
220 |
+
</main>
|
221 |
+
</div>
|
222 |
+
|
223 |
+
<!-- Modal plein écran pour les sauvegardes -->
|
224 |
+
<div id="savedModal">
|
225 |
+
<div id="savedModalContent" class="p-6">
|
226 |
+
<header class="flex justify-between items-center border-b pb-4">
|
227 |
+
<h2 class="text-2xl font-bold">Sauvegardes</h2>
|
228 |
+
<button id="closeSaved" class="text-3xl text-gray-600">×</button>
|
229 |
+
</header>
|
230 |
+
<div id="savedListContainer" class="mt-4">
|
231 |
+
<ul id="savedList" class="space-y-4">
|
232 |
+
<!-- Liste des sauvegardes insérée dynamiquement -->
|
233 |
+
</ul>
|
234 |
+
</div>
|
235 |
+
<div class="mt-6">
|
236 |
+
<button id="newExercise" class="blue-button w-full py-3 text-white font-medium rounded-lg">
|
237 |
+
Résoudre un nouvel exercice
|
238 |
+
</button>
|
239 |
+
</div>
|
240 |
+
</div>
|
241 |
+
</div>
|
242 |
+
|
243 |
+
<script>
|
244 |
+
document.addEventListener('DOMContentLoaded', () => {
|
245 |
+
// Récupération des éléments
|
246 |
+
const form = document.getElementById('problemForm');
|
247 |
+
const imageInput = document.getElementById('imageInput');
|
248 |
+
const loader = document.getElementById('loader');
|
249 |
+
const solutionSection = document.getElementById('solution');
|
250 |
+
const thoughtsContent = document.getElementById('thoughtsContent');
|
251 |
+
const answerContent = document.getElementById('answerContent');
|
252 |
+
const thoughtsToggle = document.getElementById('thoughtsToggle');
|
253 |
+
const thoughtsBox = document.getElementById('thoughtsBox');
|
254 |
+
const imagePreview = document.getElementById('imagePreview');
|
255 |
+
const previewImage = document.getElementById('previewImage');
|
256 |
+
const timestamp = document.getElementById('timestamp');
|
257 |
+
const saveButton = document.getElementById('saveButton');
|
258 |
+
const openSaved = document.getElementById('openSaved');
|
259 |
+
const closeSaved = document.getElementById('closeSaved');
|
260 |
+
const savedModal = document.getElementById('savedModal');
|
261 |
+
const savedList = document.getElementById('savedList');
|
262 |
+
const newExercise = document.getElementById('newExercise');
|
263 |
+
const mainContent = document.getElementById('mainContent'); // This variable is not used in the original logic, keeping it but it could be removed.
|
264 |
+
|
265 |
+
let startTime = null;
|
266 |
+
let timerInterval = null;
|
267 |
+
let thoughtsBuffer = '';
|
268 |
+
let answerBuffer = '';
|
269 |
+
let currentMode = null;
|
270 |
+
let updateTimeout = null;
|
271 |
+
// Removed currentEndpoint variable as it's no longer needed
|
272 |
+
|
273 |
+
// Gestion des onglets pour le choix du modèle (Removed as tabs are removed)
|
274 |
+
|
275 |
+
// Mise à jour du temps écoulé
|
276 |
+
const updateTimestamp = () => {
|
277 |
+
if (startTime) {
|
278 |
+
const seconds = Math.floor((Date.now() - startTime) / 1000);
|
279 |
+
timestamp.textContent = `${seconds}s`;
|
280 |
+
}
|
281 |
+
};
|
282 |
+
const startTimer = () => { startTime = Date.now(); timerInterval = setInterval(updateTimestamp, 1000); updateTimestamp(); };
|
283 |
+
const stopTimer = () => { clearInterval(timerInterval); startTime = null; timestamp.textContent = ''; };
|
284 |
+
|
285 |
+
// Affichage de l'image sélectionnée
|
286 |
+
const handleFileSelect = file => {
|
287 |
+
if (!file) return;
|
288 |
+
const reader = new FileReader();
|
289 |
+
reader.onload = e => {
|
290 |
+
previewImage.src = e.target.result;
|
291 |
+
imagePreview.classList.remove('hidden');
|
292 |
+
};
|
293 |
+
reader.readAsDataURL(file);
|
294 |
+
};
|
295 |
+
|
296 |
+
thoughtsToggle.addEventListener('click', () => { thoughtsBox.classList.toggle('open'); });
|
297 |
+
imageInput.addEventListener('change', e => handleFileSelect(e.target.files[0]));
|
298 |
+
|
299 |
+
// Gestion du glisser-déposer
|
300 |
+
const dropZone = document.querySelector('.uploadArea');
|
301 |
+
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('border-blue-400'); });
|
302 |
+
dropZone.addEventListener('dragleave', e => { e.preventDefault(); dropZone.classList.remove('border-blue-400'); });
|
303 |
+
dropZone.addEventListener('drop', e => { e.preventDefault(); dropZone.classList.remove('border-blue-400'); handleFileSelect(e.dataTransfer.files[0]); });
|
304 |
+
|
305 |
+
// Fonction pour appliquer la coloration syntaxique
|
306 |
+
const applyHighlighting = () => {
|
307 |
+
document.querySelectorAll('pre code').forEach((block) => {
|
308 |
+
hljs.highlightBlock(block);
|
309 |
+
});
|
310 |
+
};
|
311 |
+
|
312 |
+
// Rendu MathJax et mise à jour de l'affichage
|
313 |
+
const typesetAnswerIfReady = async () => {
|
314 |
+
if (window.mathJaxReady) {
|
315 |
+
MathJax.startup.document.elements = [document.getElementById('answerContent')];
|
316 |
+
await MathJax.typesetPromise();
|
317 |
+
applyHighlighting();
|
318 |
+
answerContent.scrollTop = answerContent.scrollHeight;
|
319 |
+
} else { setTimeout(typesetAnswerIfReady, 200); }
|
320 |
+
};
|
321 |
+
|
322 |
+
const updateDisplay = async () => {
|
323 |
+
thoughtsContent.innerHTML = marked.parse(thoughtsBuffer);
|
324 |
+
answerContent.innerHTML = marked.parse(answerBuffer);
|
325 |
+
await typesetAnswerIfReady();
|
326 |
+
updateTimeout = null;
|
327 |
+
};
|
328 |
+
|
329 |
+
const scheduleUpdate = () => { if (!updateTimeout) updateTimeout = setTimeout(updateDisplay, 200); };
|
330 |
+
|
331 |
+
marked.setOptions({
|
332 |
+
gfm: true,
|
333 |
+
breaks: true,
|
334 |
+
highlight: function(code, lang) {
|
335 |
+
if (lang && hljs.getLanguage(lang)) {
|
336 |
+
try {
|
337 |
+
return hljs.highlight(code, { language: lang }).value;
|
338 |
+
} catch (error) {}
|
339 |
+
}
|
340 |
+
return code;
|
341 |
+
}
|
342 |
+
});
|
343 |
+
|
344 |
+
// Creation of content elements (This part wasn't directly used in the streaming logic before, keeping it just in case it was intended for future use, but the current streaming logic builds markdown directly)
|
345 |
+
const createContentElement = (content, type) => {
|
346 |
+
const div = document.createElement('div');
|
347 |
+
div.className = `content-${type}`;
|
348 |
+
|
349 |
+
switch(type) {
|
350 |
+
case 'text':
|
351 |
+
div.innerHTML = marked.parse(content);
|
352 |
+
break;
|
353 |
+
case 'code':
|
354 |
+
div.innerHTML = `<pre><code>${content}</code></pre>`;
|
355 |
+
break;
|
356 |
+
case 'result':
|
357 |
+
div.innerHTML = `<div class="code-execution-result">${content}</div>`;
|
358 |
+
break;
|
359 |
+
case 'image':
|
360 |
+
div.innerHTML = `<img src="data:image/png;base64,${content}" />`;
|
361 |
+
break;
|
362 |
+
default:
|
363 |
+
div.innerHTML = marked.parse(content);
|
364 |
+
}
|
365 |
+
|
366 |
+
return div;
|
367 |
+
};
|
368 |
+
|
369 |
+
// Envoi de l'image pour résolution
|
370 |
+
form.addEventListener('submit', async e => {
|
371 |
+
e.preventDefault();
|
372 |
+
const file = imageInput.files[0];
|
373 |
+
if (!file) {
|
374 |
+
Swal.fire({
|
375 |
+
icon: 'error',
|
376 |
+
title: 'Image manquante',
|
377 |
+
text: 'Veuillez sélectionner une image.'
|
378 |
+
});
|
379 |
+
return;
|
380 |
+
}
|
381 |
+
|
382 |
+
startTimer();
|
383 |
+
loader.classList.remove('hidden');
|
384 |
+
solutionSection.classList.add('hidden');
|
385 |
+
thoughtsContent.innerHTML = '';
|
386 |
+
answerContent.innerHTML = '';
|
387 |
+
thoughtsBuffer = '';
|
388 |
+
answerBuffer = '';
|
389 |
+
currentMode = null; // Reset mode
|
390 |
+
|
391 |
+
// thoughtsBox starts open by default, keep it open during processing
|
392 |
+
thoughtsBox.classList.add('open');
|
393 |
+
|
394 |
+
const formData = new FormData();
|
395 |
+
formData.append('image', file);
|
396 |
+
|
397 |
+
try {
|
398 |
+
// Hardcode the endpoint to /solved
|
399 |
+
const response = await fetch('/solved', { method: 'POST', body: formData });
|
400 |
+
|
401 |
+
if (!response.body) {
|
402 |
+
throw new Error('Response body is not available (e.g., not a streaming response)');
|
403 |
+
}
|
404 |
+
|
405 |
+
const reader = response.body.getReader();
|
406 |
+
const decoder = new TextDecoder();
|
407 |
+
let buffer = '';
|
408 |
+
|
409 |
+
const processChunk = async chunk => {
|
410 |
+
buffer += decoder.decode(chunk, { stream: true });
|
411 |
+
const lines = buffer.split('\n\n');
|
412 |
+
buffer = lines.pop();
|
413 |
+
|
414 |
+
for (const line of lines) {
|
415 |
+
if (!line.startsWith('data:')) {
|
416 |
+
console.warn('Skipping non-data line:', line); // Log non-data lines
|
417 |
+
continue;
|
418 |
+
}
|
419 |
+
try {
|
420 |
+
const data = JSON.parse(line.slice(5));
|
421 |
+
|
422 |
+
if (data.mode) {
|
423 |
+
currentMode = data.mode;
|
424 |
+
loader.classList.add('hidden');
|
425 |
+
solutionSection.classList.remove('hidden');
|
426 |
+
}
|
427 |
+
|
428 |
+
if (data.content !== undefined) { // Check for undefined to allow empty strings
|
429 |
+
// Gestion différenciée selon le type de contenu
|
430 |
+
if (currentMode === 'thinking') {
|
431 |
+
// For thinking mode, just append text
|
432 |
+
thoughtsBuffer += data.content;
|
433 |
+
} else if (currentMode === 'answering') {
|
434 |
+
// For answering mode, handle different types
|
435 |
+
switch(data.type) {
|
436 |
+
case 'code':
|
437 |
+
answerBuffer += "\n```\n" + data.content + "\n```\n";
|
438 |
+
break;
|
439 |
+
case 'result':
|
440 |
+
// Format results clearly, handling multiple lines
|
441 |
+
const formattedResult = data.content.split('\n').map(line => `> ${line}`).join('\n');
|
442 |
+
answerBuffer += "\n" + formattedResult + "\n";
|
443 |
+
break;
|
444 |
+
case 'image':
|
445 |
+
// Include images as markdown images
|
446 |
+
answerBuffer += `\n\n`;
|
447 |
+
break;
|
448 |
+
case 'text': // Explicitly handle text within answering mode
|
449 |
+
default: // Default behavior is to append text
|
450 |
+
answerBuffer += data.content;
|
451 |
+
break;
|
452 |
+
}
|
453 |
+
}
|
454 |
+
}
|
455 |
|
456 |
+
if (data.error) {
|
457 |
+
answerBuffer += `\n**Erreur:** ${data.error}\n`;
|
458 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
+
} catch (e) {
|
461 |
+
console.error('Error parsing JSON data:', line.slice(5), e);
|
462 |
+
// Optionally append an error message to the output
|
463 |
+
if (currentMode === 'thinking') { thoughtsBuffer += `\n[Parsing Error]`; }
|
464 |
+
else { answerBuffer += `\n[Parsing Error]`; }
|
465 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
}
|
467 |
|
468 |
+
scheduleUpdate(); // Schedule display update after processing chunks
|
469 |
+
};
|
470 |
+
|
471 |
+
// Start processing the stream
|
472 |
+
while (true) {
|
473 |
+
const { done, value } = await reader.read();
|
474 |
+
if (done) {
|
475 |
+
// Process any remaining buffer
|
476 |
+
if (buffer) {
|
477 |
+
try {
|
478 |
+
// Attempt to parse the last bit if it looks like a data line
|
479 |
+
if (buffer.startsWith('data:')) {
|
480 |
+
const data = JSON.parse(buffer.slice(5));
|
481 |
+
if (data.content !== undefined) {
|
482 |
+
if (currentMode === 'thinking') { thoughtsBuffer += data.content; }
|
483 |
+
else if (currentMode === 'answering') { answerBuffer += data.content; }
|
484 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
} else {
|
486 |
+
// Handle cases where the buffer is not a complete data line (e.g., partial line)
|
487 |
+
console.warn('Remaining buffer is not a complete data line:', buffer);
|
488 |
+
// Decide how to handle partial data - maybe discard or append as raw? Appending as raw might break markdown. Discarding is safer.
|
489 |
}
|
490 |
+
} catch (e) {
|
491 |
+
console.error('Error processing final buffer:', e);
|
492 |
+
}
|
493 |
+
}
|
494 |
+
scheduleUpdate(); // Final display update
|
495 |
+
break; // Exit loop
|
496 |
+
}
|
497 |
+
await processChunk(value);
|
498 |
+
}
|
499 |
+
|
500 |
+
stopTimer(); // Stop timer when stream is done
|
501 |
+
} catch (error) {
|
502 |
+
console.error('Erreur de Fetch ou du Stream:', error);
|
503 |
+
Swal.fire({
|
504 |
+
icon: 'error',
|
505 |
+
title: 'Erreur de connexion ou de traitement',
|
506 |
+
text: `Une erreur est survenue lors du traitement de votre demande: ${error.message}`
|
507 |
+
});
|
508 |
+
loader.classList.add('hidden');
|
509 |
+
stopTimer(); // Ensure timer stops on error
|
510 |
+
solutionSection.classList.remove('hidden'); // Show section maybe with error message
|
511 |
+
if(answerBuffer === '') { // If no output yet, put error in answer section
|
512 |
+
answerContent.innerHTML = `<div class="text-red-500">Une erreur est survenue: ${error.message}</div>`;
|
513 |
+
} else { // If some output exists, append error
|
514 |
+
answerBuffer += `\n\n<div class="text-red-500">Une erreur est survenue: ${error.message}</div>`;
|
515 |
+
scheduleUpdate(); // Update display with error
|
516 |
+
}
|
517 |
+
}
|
518 |
+
});
|
519 |
+
|
520 |
+
|
521 |
+
// Sauvegarde de la solution avec SweetAlert2
|
522 |
+
saveButton.addEventListener('click', () => {
|
523 |
+
Swal.fire({
|
524 |
+
title: 'Sauvegarder la solution',
|
525 |
+
input: 'text',
|
526 |
+
inputLabel: 'Nom de la sauvegarde',
|
527 |
+
inputPlaceholder: 'Entrez un nom pour cette sauvegarde',
|
528 |
+
showCancelButton: true,
|
529 |
+
confirmButtonText: 'Sauvegarder',
|
530 |
+
cancelButtonText: 'Annuler'
|
531 |
+
}).then((result) => {
|
532 |
+
if (result.isConfirmed && result.value) {
|
533 |
+
const saveName = result.value;
|
534 |
+
const saveData = {
|
535 |
+
answer: answerContent.innerHTML, // Save the rendered HTML
|
536 |
+
thinking: thoughtsContent.innerHTML, // Save the rendered HTML
|
537 |
+
date: new Date().toLocaleString()
|
538 |
+
};
|
539 |
+
let savedExercises = JSON.parse(localStorage.getItem('savedExercises') || '{}');
|
540 |
+
savedExercises[saveName] = saveData;
|
541 |
+
localStorage.setItem('savedExercises', JSON.stringify(savedExercises));
|
542 |
+
Swal.fire({
|
543 |
+
icon: 'success',
|
544 |
+
title: 'Sauvegarde réussie',
|
545 |
+
text: 'Votre solution a bien été sauvegardée !',
|
546 |
+
timer: 2000,
|
547 |
+
showConfirmButton: false
|
548 |
});
|
549 |
+
}
|
550 |
});
|
551 |
+
});
|
552 |
+
|
553 |
+
// Chargement des sauvegardes dans le modal
|
554 |
+
const loadSavedList = () => {
|
555 |
+
savedList.innerHTML = '';
|
556 |
+
const savedExercises = JSON.parse(localStorage.getItem('savedExercises') || '{}');
|
557 |
+
|
558 |
+
if (Object.keys(savedExercises).length === 0) {
|
559 |
+
savedList.innerHTML = '<li class="text-gray-500 text-center py-8">Aucune sauvegarde disponible</li>';
|
560 |
+
return;
|
561 |
+
}
|
562 |
+
|
563 |
+
// Sort by date, newest first (optional but nice)
|
564 |
+
const sortedEntries = Object.entries(savedExercises).sort(([,a], [,b]) => new Date(b.date) - new Date(a.date));
|
565 |
+
|
566 |
+
|
567 |
+
for (const [name, data] of sortedEntries) {
|
568 |
+
const li = document.createElement('li');
|
569 |
+
li.className = 'border-b pb-2';
|
570 |
+
li.innerHTML = `
|
571 |
+
<div class="flex justify-between items-center">
|
572 |
+
<button class="text-left text-blue-600 hover:underline" data-save="${name}">
|
573 |
+
${name} <span class="text-gray-500 text-xs">(${data.date})</span>
|
574 |
+
</button>
|
575 |
+
<button class="text-red-500 hover:text-red-700" data-delete="${name}">
|
576 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
577 |
+
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
|
578 |
+
</svg>
|
579 |
+
</button>
|
580 |
+
</div>
|
581 |
+
`;
|
582 |
+
savedList.appendChild(li);
|
583 |
+
}
|
584 |
+
};
|
585 |
+
|
586 |
+
// Gestion des clics sur les sauvegardes
|
587 |
+
savedList.addEventListener('click', (e) => {
|
588 |
+
// Chargement d'une sauvegarde
|
589 |
+
if (e.target && e.target.dataset.save) {
|
590 |
+
const saveName = e.target.dataset.save;
|
591 |
+
const savedExercises = JSON.parse(localStorage.getItem('savedExercises') || '{}');
|
592 |
+
const data = savedExercises[saveName];
|
593 |
+
if (data) {
|
594 |
+
// Hide the form and loader, show the solution section
|
595 |
+
form.classList.add('hidden');
|
596 |
+
loader.classList.add('hidden');
|
597 |
+
solutionSection.classList.remove('hidden');
|
598 |
+
|
599 |
+
// Load the saved HTML content
|
600 |
+
thoughtsContent.innerHTML = data.thinking;
|
601 |
+
answerContent.innerHTML = data.answer;
|
602 |
+
|
603 |
+
// Close the modal
|
604 |
+
savedModal.classList.remove('active');
|
605 |
+
|
606 |
+
// Re-render MathJax and apply highlighting to the loaded HTML
|
607 |
+
// Use MathJax.typesetPromise() on the specific elements
|
608 |
+
if (window.mathJaxReady) {
|
609 |
+
MathJax.startup.document.elements = [thoughtsContent, answerContent]; // Target both potentially
|
610 |
+
MathJax.typesetPromise().then(() => {
|
611 |
+
applyHighlighting(); // Apply highlighting after MathJax
|
612 |
+
}).catch((err) => console.error("MathJax typesetting failed:", err));
|
613 |
+
} else {
|
614 |
+
console.warn("MathJax not ready yet, cannot typeset saved content.");
|
615 |
+
}
|
616 |
+
|
617 |
+
// Ensure thoughts box is open when viewing a saved solution
|
618 |
+
thoughtsBox.classList.add('open');
|
619 |
+
|
620 |
+
// Reset buffers and timer as this is static content
|
621 |
+
thoughtsBuffer = ''; // Or load from saved data if needed for re-processing
|
622 |
+
answerBuffer = ''; // Or load from saved data if needed for re-processing
|
623 |
+
stopTimer();
|
624 |
+
timestamp.textContent = data.date; // Show saved date as timestamp
|
625 |
+
}
|
626 |
+
}
|
627 |
+
|
628 |
+
// Suppression d'une sauvegarde
|
629 |
+
if (e.target && (e.target.dataset.delete || e.target.closest('[data-delete]'))) {
|
630 |
+
const deleteName = e.target.dataset.delete || e.target.closest('[data-delete]').dataset.delete;
|
631 |
+
|
632 |
+
Swal.fire({
|
633 |
+
title: 'Êtes-vous sûr ?',
|
634 |
+
text: "Cette sauvegarde sera définitivement supprimée.",
|
635 |
+
icon: 'warning',
|
636 |
+
showCancelButton: true,
|
637 |
+
confirmButtonColor: '#3085d6',
|
638 |
+
cancelButtonColor: '#d33',
|
639 |
+
confirmButtonText: 'Oui, supprimer',
|
640 |
+
cancelButtonText: 'Annuler'
|
641 |
+
}).then((result) => {
|
642 |
+
if (result.isConfirmed) {
|
643 |
+
const savedExercises = JSON.parse(localStorage.getItem('savedExercises') || '{}');
|
644 |
+
delete savedExercises[deleteName];
|
645 |
+
localStorage.setItem('savedExercises', JSON.stringify(savedExercises));
|
646 |
+
|
647 |
+
Swal.fire(
|
648 |
+
'Supprimé !',
|
649 |
+
'La sauvegarde a été supprimée.',
|
650 |
+
'success'
|
651 |
+
);
|
652 |
+
|
653 |
+
loadSavedList(); // Refresh the list in the modal
|
654 |
+
// If the currently viewed solution is the one being deleted, clear it
|
655 |
+
// (Optional, maybe better to just let them view it until they start a new one)
|
656 |
+
}
|
657 |
+
});
|
658 |
+
}
|
659 |
+
});
|
660 |
+
|
661 |
+
// Ouverture / fermeture du modal de sauvegardes
|
662 |
+
openSaved.addEventListener('click', () => { loadSavedList(); savedModal.classList.add('active'); });
|
663 |
+
closeSaved.addEventListener('click', () => { savedModal.classList.remove('active'); });
|
664 |
+
|
665 |
+
// Bouton présent uniquement dans le modal pour lancer un nouvel exercice
|
666 |
+
newExercise.addEventListener('click', () => {
|
667 |
+
// Reset form and hide solution
|
668 |
+
form.reset();
|
669 |
+
form.classList.remove('hidden');
|
670 |
+
solutionSection.classList.add('hidden');
|
671 |
+
imagePreview.classList.add('hidden'); // Hide image preview
|
672 |
+
previewImage.src = ''; // Clear image source
|
673 |
+
|
674 |
+
// Clear content areas and buffers
|
675 |
+
thoughtsContent.innerHTML = '';
|
676 |
+
answerContent.innerHTML = '';
|
677 |
+
thoughtsBuffer = '';
|
678 |
+
answerBuffer = '';
|
679 |
+
currentMode = null; // Reset mode
|
680 |
+
|
681 |
+
// Stop timer and clear timestamp
|
682 |
+
stopTimer();
|
683 |
+
timestamp.textContent = '';
|
684 |
+
|
685 |
+
// Ensure thoughts box is collapsed for a new exercise
|
686 |
+
thoughtsBox.classList.remove('open');
|
687 |
+
|
688 |
+
|
689 |
+
// Close the modal
|
690 |
+
savedModal.classList.remove('active');
|
691 |
+
});
|
692 |
+
});
|
693 |
+
</script>
|
694 |
</body>
|
695 |
</html>
|