File size: 7,156 Bytes
52b6b11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interactive Code Explorer - V5 Grouped Outline - Mobile Friendly (Refined V1)</title>
    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Inter Font -->
    <link rel="stylesheet" href="https://rsms.me/inter/inter.css">
    <!-- Prism.js CSS (Okaidia Theme) -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-okaidia.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="style.css">
</head>
<body class="min-h-screen flex flex-col items-center justify-center antialiased">

    <!-- Main Container for the Code Explorer -->
    <div class="container mx-auto p-4 md:p-6 max-w-7xl w-full">
      <header class="mb-6 md:mb-8 text-center">
        <h1 class="text-3xl sm:text-4xl font-bold text-slate-800">Interactive Code Journey</h1>
        <p class="text-md sm:text-lg text-slate-600 mt-2">Step through the code, understand by doing. Click on code lines or outline to navigate.</p>
      </header>

      <div class="flex flex-col md:flex-row gap-4 md:items-stretch">

        <!-- ASIDE: Steps Outline Container -->
        <aside id="stepsOutlineContainer" class="w-full md:w-1/3 lg:w-1/4 bg-white shadow-xl rounded-xl flex flex-col overflow-hidden md:max-h-[calc(65vh+136px)]">
            <!-- Desktop Title -->
            <div class="p-4 border-b border-slate-200 hidden md:block">
                <h3 class="text-lg font-semibold text-slate-700">Journey Outline</h3>
            </div>
            <!-- Mobile Active Group/Step Info -->
            <div id="mobileCurrentStepDisplayContainer" class="p-3 border-b border-slate-200 md:hidden">
                <h4 class="text-xs sm:text-sm font-semibold text-slate-700">Current Section: <span id="mobileCurrentGroupText" class="text-sky-600 font-bold"></span></h4>
                <p class="text-sm text-slate-600 mt-1">Step: <span id="mobileCurrentStepText" class="text-sky-700 font-medium"></span></p>
            </div>
            <nav class="hidden md:block flex-grow overflow-y-auto custom-scrollbar p-3 sm:p-4">
                <ul id="stepsOutline" class="space-y-0"> <!-- Reduced space-y for tighter group layout -->
                </ul>
            </nav>
        </aside>

        <!-- MAIN: Code Explorer Content -->
        <main id="codeExplorer" class="w-full md:w-2/3 lg:w-3/4 bg-white shadow-2xl rounded-xl overflow-hidden flex flex-col">
          <div class="bg-slate-800 text-white p-3 sm:p-4 flex justify-between items-center border-b border-slate-700">
            <h2 id="snippetTitle" class="text-lg sm:text-xl font-semibold truncate pr-2">JS Snippet: Interactive Counter</h2>
            <div class="flex items-center space-x-2 sm:space-x-3">
              <button id="resetBtn" title="Reset to Start" class="p-2 rounded-full hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-sky-500 transition-colors">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
                  <path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" />
                </svg>
              </button>
              <span id="progressIndicator" class="text-xs sm:text-sm bg-slate-700 px-2 py-1 rounded-md">Step 1 / N</span>
            </div>
          </div>

          <div class="md:flex flex-1 min-h-0"> <!-- This flex container handles code/explanation layout -->
            <!-- Code View Pane -->
            <div class="md:w-3/5 bg-gray-900 text-gray-300 font-mono text-xs sm:text-sm relative overflow-y-auto custom-scrollbar max-h-[45vh] md:max-h-[65vh]">
              <div id="codeLinesContainer" class="p-2">
                <!-- Code lines will be rendered here by JS -->
              </div>
            </div>

            <!-- Explanation Pane -->
            <div class="md:w-2/5 bg-slate-100 p-4 sm:p-6 overflow-y-auto custom-scrollbar max-h-[45vh] md:max-h-[65vh]">
              <div id="explanationStepCategoryContainer" class="mb-2 empty:hidden">
                <!-- Category badge will be inserted here by JS -->
              </div>
              <h3 id="explanationStepTitle" class="text-lg sm:text-xl font-semibold text-sky-700 mb-1 sm:mb-2">Loading...</h3>
              <p id="explanationMeta" class="text-xs text-slate-500 mb-3 sm:mb-4">Initializing explorer...</p>
              <div id="explanationText" class="text-slate-700 text-sm space-y-3 leading-relaxed prose prose-sm max-w-none">
                <p>Please wait while the code explorer initializes.</p>
              </div>
            </div>
          </div>

          <div class="bg-slate-200 p-3 sm:p-4 flex justify-between items-center border-t border-slate-300">
            <button id="prevBtn" class="px-4 py-2 sm:px-5 sm:py-2.5 bg-slate-600 text-white rounded-lg hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-500 focus:ring-offset-2 transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-2 shadow-md hover:shadow-lg disabled:shadow-none text-sm sm:text-base">
              <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-4 h-4 sm:w-5 sm:h-5">
                <path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18" />
              </svg>
              <span>Previous</span>
            </button>
            <button id="nextBtn" class="px-4 py-2 sm:px-5 sm:py-2.5 bg-sky-600 text-white rounded-lg hover:bg-sky-700 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2 transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-2 shadow-md hover:shadow-lg disabled:shadow-none text-sm sm:text-base">
              <span>Next</span>
              <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-4 h-4 sm:w-5 sm:h-5">
                <path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3" />
              </svg>
            </button>
          </div>
        </main>
      </div>

      <footer class="mt-6 md:mt-8 text-center text-xs sm:text-sm text-slate-500">
        <p>Variation 5 (Grouped Outline): Interactive Code Walkthrough. Crafted with Tailwind CSS & Vanilla JS. Syntax highlighting by Prism.js.</p>
      </footer>
    </div>

    <!-- Prism.js Core (must be before language components and your script) -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
    <!-- Prism.js JavaScript Language Component -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"></script>
    <script src="script.js" defer></script>

</body>
</html>