Add tutorial route; gate lib workspace for superusers; Py worker v4

- Serve /tutorial and add tutorial.html/tutorial.js assets
- Fetch auth role; hide lib from non-superusers in tree and restored tabs
- Cache workspace Python sources briefly for Py worker
- Pyodide worker and home/index links/styling tweaks

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-10 01:14:51 +12:00
parent 7d682cce8d
commit 6fc651ad72
8 changed files with 770 additions and 16 deletions

250
src/static/tutorial.html Normal file
View File

@@ -0,0 +1,250 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Tutorial</title>
<link rel="icon" href="data:,">
<style>
* { box-sizing: border-box; }
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #0f172a;
color: #e2e8f0;
min-height: 100dvh;
}
.page {
max-width: 1100px;
margin: 0 auto;
padding: 1rem;
display: grid;
gap: 0.9rem;
}
.topbar {
display: flex;
gap: 0.6rem;
flex-wrap: wrap;
align-items: center;
}
.btn {
border: 1px solid #334155;
background: #1e293b;
color: #e2e8f0;
border-radius: 8px;
text-decoration: none;
padding: 0.45rem 0.7rem;
cursor: pointer;
font-size: 0.92rem;
}
.btn.primary {
background: #2563eb;
border-color: #2563eb;
}
.layout {
display: grid;
grid-template-columns: 1fr;
gap: 0.9rem;
min-height: 70dvh;
}
.card {
border: 1px solid #334155;
border-radius: 12px;
background: #111827;
padding: 0.8rem;
min-height: 0;
}
.hint { color: #94a3b8; font-size: 0.9rem; margin: 0.4rem 0 0.7rem; white-space: pre-wrap; }
.guided-grid {
display: grid;
grid-template-columns: 1fr 320px;
gap: 0.8rem;
margin-bottom: 0.9rem;
}
.demo-code {
margin: 0.55rem 0 0;
border: 1px solid #334155;
background: #020617;
border-radius: 8px;
padding: 0.6rem;
min-height: 280px;
overflow: auto;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.84rem;
line-height: 1.45;
white-space: pre;
}
.demo-line {
display: block;
padding: 0 0.2rem;
border-radius: 4px;
color: #cbd5e1;
}
.demo-line.active {
background: rgba(59, 130, 246, 0.18);
color: #dbeafe;
outline: 1px solid rgba(59, 130, 246, 0.35);
}
.demo-controls {
display: grid;
gap: 0.65rem;
margin-top: 0.65rem;
padding: 0.7rem;
border: 1px solid #334155;
border-radius: 10px;
background: #0b1220;
}
.demo-controls label {
display: grid;
gap: 0.2rem;
color: #e2e8f0;
font-size: 0.95rem;
font-weight: 600;
}
.demo-controls .control-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.5rem;
}
.demo-controls .value-badge {
min-width: 52px;
text-align: center;
background: #1d4ed8;
color: white;
border: 1px solid rgba(255,255,255,0.2);
border-radius: 999px;
padding: 0.1rem 0.45rem;
font-size: 0.8rem;
}
.demo-controls input[type="range"] {
width: 100%;
accent-color: #3b82f6;
height: 1.1rem;
}
.demo-controls select {
width: 100%;
border: 1px solid #475569;
border-radius: 8px;
background: #020617;
color: #e2e8f0;
padding: 0.5rem 0.55rem;
font-size: 0.92rem;
}
.guide-explain {
border: 1px solid #334155;
background: #020617;
border-radius: 8px;
padding: 0.65rem;
color: #cbd5e1;
min-height: 120px;
white-space: pre-wrap;
}
.guide-step {
color: #93c5fd;
font-size: 0.9rem;
margin: 0.45rem 0;
}
.hidden { display: none !important; }
.led-demo-panel {
border: 1px solid #334155;
background: #020617;
border-radius: 8px;
padding: 0.65rem;
width: fit-content;
display: inline-block;
}
.led-meta {
color: #9ca3af;
font-size: 0.82rem;
margin-bottom: 0.45rem;
display: none;
}
.led-grid {
display: grid;
grid-template-columns: repeat(16, 24px);
grid-auto-rows: 24px;
gap: 6px;
max-height: none;
overflow: visible;
align-content: start;
justify-content: start;
width: fit-content;
}
.led {
width: 24px;
height: 24px;
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.45);
}
@media (max-width: 900px) {
.guided-grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<main class="page">
<div class="topbar">
<a class="btn" href="/">Home</a>
</div>
<div class="layout">
<section class="card">
<h3 style="margin:0">Guided LED Demo</h3>
<div style="display:flex; gap:0.5rem; flex-wrap:wrap;">
<button id="begin-demo-btn" class="btn primary" type="button">Let's Get Started</button>
<button id="toggle-breakdown-btn" class="btn hidden" type="button">Show Breakdown</button>
</div>
<div class="guided-grid">
<div>
<div class="led-demo-panel">
<div id="led-meta" class="led-meta">Press Begin Demo to render the panel animation.</div>
<div id="led-grid" class="led-grid"></div>
</div>
</div>
<div>
<div class="demo-controls">
<label>Pattern
<select id="pattern-select">
<option value="plasma">Plasma Swirl</option>
<option value="rainbow">Rainbow Orbit</option>
</select>
</label>
<label>
<span class="control-head">Speed <span id="speed-value" class="value-badge"></span></span>
<input id="speed-slider" type="range" min="0.8" max="3.2" step="0.1" value="1.6" />
</label>
<label>
<span class="control-head">Wave Width <span id="width-value" class="value-badge"></span></span>
<input id="width-slider" type="range" min="0.2" max="0.8" step="0.02" value="0.45" />
</label>
<label>
<span class="control-head">Brightness <span id="brightness-value" class="value-badge"></span></span>
<input id="brightness-slider" type="range" min="80" max="230" step="5" value="170" />
</label>
</div>
</div>
</div>
<div id="learning-content" class="hidden">
<div id="breakdown-panel" class="hidden">
<div style="display:flex; gap:0.5rem; flex-wrap:wrap; margin-top:0.2rem;">
<button id="prev-part-btn" class="btn" type="button">Prev Part</button>
<button id="next-part-btn" class="btn" type="button">Next Part</button>
</div>
<div class="guided-grid" style="margin-top:0.55rem;">
<div>
<div id="guide-step" class="guide-step"></div>
<div id="demo-code" class="demo-code"></div>
</div>
<div>
<div id="guide-explain" class="guide-explain"></div>
</div>
</div>
</div>
</div>
</section>
</div>
</main>
<script type="module" src="/static/tutorial.js?v=2"></script>
</body>
</html>