@@ -214,7 +214,11 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
214214 PARI_COLLAPSED : 'PARI ▼' ,
215215 PARI_EXPANDED : 'PARI ▲' ,
216216 PARI_LOADING : 'Loading PARI...' ,
217- PARI_ERROR : 'PARI Error'
217+ PARI_ERROR : 'PARI Error' ,
218+ LEAN_COLLAPSED : 'LEAN ▼' ,
219+ LEAN_EXPANDED : 'LEAN ▲' ,
220+ LEAN_LOADING : 'Loading LEAN...' ,
221+ LEAN_ERROR : 'LEAN Error'
218222 } ;
219223
220224 const CSS_CLASSES = {
@@ -224,6 +228,7 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
224228 PROGRAM_CODE : 'loda-program-code' ,
225229 PROGRAM_BUTTONS : 'loda-program-buttons' ,
226230 PARI_CONTAINER : 'loda-pari-container' ,
231+ LEAN_CONTAINER : 'loda-pari-container' ,
227232 LANGUAGE_ASM : 'language-asm'
228233 } ;
229234
@@ -338,10 +343,10 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
338343 }
339344 }
340345
341- // --- Fetch PARI export ---
342- async function fetchPariExport ( sequenceId , programCode ) {
346+ // --- Fetch export in specified format ---
347+ async function fetchExport ( sequenceId , programCode , format ) {
343348 try {
344- const url = `${ API_BASE_URL } /programs/export?format=pari ` ;
349+ const url = `${ API_BASE_URL } /programs/export?format=${ format } ` ;
345350 const resp = await fetch ( url , {
346351 method : 'POST' ,
347352 headers : {
@@ -353,7 +358,7 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
353358 const data = await resp . json ( ) ;
354359 return data . status === 'success' ? data . output : null ;
355360 } catch ( error ) {
356- console . error ( ' Error fetching PARI export:' , error ) ;
361+ console . error ( ` Error fetching ${ format . toUpperCase ( ) } export:` , error ) ;
357362 return null ;
358363 }
359364 }
@@ -375,7 +380,7 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
375380 button . disabled = true ;
376381
377382 // Fetch the PARI export
378- const pariCode = await fetchPariExport ( sequenceId , programCode ) ;
383+ const pariCode = await fetchExport ( sequenceId , programCode , 'pari' ) ;
379384
380385 if ( pariCode ) {
381386 // Create PARI container
@@ -397,6 +402,45 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
397402 button . disabled = false ;
398403 }
399404
405+ // --- Toggle LEAN export display ---
406+ async function toggleLeanExport ( sequenceId , button , programContainer , programCode ) {
407+ const leanId = `loda-lean-${ sequenceId } ` ;
408+ let leanContainer = document . getElementById ( leanId ) ;
409+
410+ if ( leanContainer ) {
411+ // If LEAN is already shown, hide it
412+ leanContainer . remove ( ) ;
413+ button . textContent = BUTTON_STATES . LEAN_COLLAPSED ;
414+ return ;
415+ }
416+
417+ // Show loading state
418+ button . textContent = BUTTON_STATES . LEAN_LOADING ;
419+ button . disabled = true ;
420+
421+ // Fetch the LEAN export
422+ const leanCode = await fetchExport ( sequenceId , programCode , 'lean' ) ;
423+
424+ if ( leanCode ) {
425+ // Create LEAN container
426+ leanContainer = document . createElement ( 'div' ) ;
427+ leanContainer . id = leanId ;
428+ leanContainer . className = CSS_CLASSES . LEAN_CONTAINER ;
429+ leanContainer . textContent = leanCode ;
430+
431+ programContainer . appendChild ( leanContainer ) ;
432+
433+ button . textContent = BUTTON_STATES . LEAN_EXPANDED ;
434+ } else {
435+ button . textContent = BUTTON_STATES . LEAN_ERROR ;
436+ setTimeout ( ( ) => {
437+ button . textContent = BUTTON_STATES . LEAN_COLLAPSED ;
438+ } , DEFAULT_CONFIG . ERROR_DISPLAY_DURATION ) ;
439+ }
440+
441+ button . disabled = false ;
442+ }
443+
400444 // --- Render sequence list ---
401445 function renderSequenceList ( results ) {
402446 const list = document . getElementById ( 'sequence-list' ) ;
@@ -487,6 +531,12 @@ <h1 class="post-title">Integer Sequences and LODA Programs</h1>
487531 pariButton . textContent = BUTTON_STATES . PARI_COLLAPSED ;
488532 pariButton . onclick = ( ) => togglePariExport ( sequenceId , pariButton , programContainer , code ) ;
489533 buttonsContainer . appendChild ( pariButton ) ;
534+
535+ const leanButton = document . createElement ( 'button' ) ;
536+ leanButton . className = CSS_CLASSES . LODA_BUTTON ;
537+ leanButton . textContent = BUTTON_STATES . LEAN_COLLAPSED ;
538+ leanButton . onclick = ( ) => toggleLeanExport ( sequenceId , leanButton , programContainer , code ) ;
539+ buttonsContainer . appendChild ( leanButton ) ;
490540 }
491541
492542 programContainer . appendChild ( codeContainer ) ;
0 commit comments