holder + scad: SCAD source editor on /holder + new /scad universal renderer

Phase 2 — SCAD editor on /holder
================================
Some adjustments need more control than the parameter form gives
(e.g. tweaking the .scad logic itself). A collapsible CodeMirror-based
editor now slides up from the bottom of the viewport when you click
the "</> Source" button at the bottom-right.

- holder.html / holder.css: editor panel, toggle button, Reset and
  Close buttons. CodeMirror 5 loaded from cdnjs (single CSS + JS
  pair, clike mode for syntax highlighting since OpenSCAD is C-like).
- holder-app.js: lazy-initialises the editor on first show, fetches
  bundled source from /api/holder/source, tracks whether the editor
  content has been modified ("modified" tag in the panel title).
  When the editor is visible AND content differs from bundled,
  _doRender() switches from /api/holder/render -> /api/scad/render
  with {source, params}. Cell-count cap doesn't apply in that mode
  (the source may not even use the holder schema).

Phase 3 — Universal OpenSCAD playground at /scad
================================================
A standalone page for rendering arbitrary OpenSCAD. Paste code, click
Render (or Ctrl+Enter), see STL in the same Three.js viewer the
holder uses. Useful for prototyping new generators before wiring
them into a parameter form.

- New page: static/scad.html + scad.css + js/scad-app.js. Reuses
  holder-viewer.js (the Three.js scene module is generic enough).
- "Load example" populates a 6-hole rounded bracket so new users
  can verify the renderer works in two clicks.
- Same progress UI (elapsed timer + indeterminate bar + Cancel
  via AbortController) as /holder.
- Top nav now has Holder / Busbars / SCAD on every page.

Backend (shared by phase 2 & 3)
================================
- holder.py: split _run_openscad() out of render_stl(). New
  render_source(source, params=None) writes the source to a temp
  file and renders it; enforces MAX_SOURCE_BYTES (default 512 KB)
  and RENDER_TIMEOUT but skips the cell-count cap. New bundled_source()
  returns the hex_cell.scad text for editor pre-population.
- app.py: GET /api/holder/source returns the bundled .scad text.
  POST /api/scad/render takes {source, params?} and returns STL +
  X-Holder-Dimensions header. ValueError -> 400, RuntimeError -> 500.
  _stl_response() factored out so both render endpoints emit the same
  headers consistently.
This commit is contained in:
wenil
2026-05-25 12:52:18 +03:00
parent 5bba0e3c4a
commit 676d976937
9 changed files with 470 additions and 29 deletions
+39
View File
@@ -165,3 +165,42 @@
#fit-verdict.fit-ok { color: #4ad97a; font-weight: 600; }
#fit-verdict.fit-bad { color: var(--danger, #d94a4a); font-weight: 600; }
/* SCAD editor — slides up from the bottom of the viewport */
.scad-toggle {
position: absolute;
bottom: 8px;
right: 8px;
font-size: 12px;
padding: 4px 10px;
z-index: 3;
}
.scad-panel {
position: absolute;
left: 0; right: 0; bottom: 0;
height: 45%;
background: var(--bg, #11141a);
border-top: 1px solid var(--border, #2a2f3a);
display: flex;
flex-direction: column;
z-index: 2;
}
.scad-panel-bar {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border-bottom: 1px solid var(--border, #2a2f3a);
font-size: 12px;
}
.scad-panel-title { flex: 1; color: var(--muted); }
.scad-dirty { color: var(--accent, #4a9eff); font-weight: 600; }
#scad-editor {
flex: 1;
overflow: hidden;
font-size: 12px;
}
#scad-editor .CodeMirror {
height: 100%;
font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}