Spaces:
Running
Running
Expanded 3D view keeps the details panel on the right, with a hide/show toggle
Browse filesFiles changed (3)
- app.js+44-26
- index.html+2-2
- style.css+24-9
241 unmodified lines242243244245245246247248120 unmodified lines369370371372373374375372373374375376377378379380381382383384385386387377378379380381382383384385388389390391392393394395396397398399400401402387388389403404405406407408393409410395396411412413414415416417418398419420421400401402422423424111 unmodified lines536537538520539522540541542543241 unmodified linesasync function getViewer() { if (viewer || viewerFailed) return viewer; try { const { createViewer } = await import(signed("./viewer.js?v=27")); const { createViewer } = await import(signed("./viewer.js?v=28")); viewer = createViewer(); viewer.setTheme(theme()); } catch (e) {120 unmodified lines }});
// Expanded 3D view: the viewer moves into a full-window layer above the whole page and back// again on close (button or Esc). It keeps its state: camera, joint positions, dots.let expanded = null; // { layer, box, view }function expandViewer(a, box, hint) {// Expanded view: the detail panel fills the window, the 3D view takes the left side and the// details (sliders, facts, Copy URL / Download) stay in a column on the right, which the// edge button hides or shows. The same corner button (or Esc) goes back. The viewer keeps// its state; on the way in it backs up to show the whole model, on the way out the panel// gets back the camera it had.const PANEL_HIDE = "M9 6l6 6-6 6", PANEL_SHOW = "M15 6l-6 6 6 6";let expanded = null; // { box, view, spot, stage }function setExpandButton(box, on) { const b = box.querySelector(".viewer-expand"); if (!b) return; b.replaceChildren(icon(on ? COLLAPSE : EXPAND)); b.setAttribute("aria-label", on ? "Exit full view" : "Expand 3D view"); b.title = on ? "Exit full view (Esc)" : "Expand";}function expandViewer(box) { if (!viewer || expanded) return; const close = el("button", { class: "icon-button", type: "button", "aria-label": "Close expanded view", title: "Close (Esc)", onclick: collapseViewer }, icon(COLLAPSE)); const stage = el("div", { class: "viewer-full-stage" }); const layer = el("div", { class: "viewer-full", role: "dialog", "aria-modal": "true", "aria-label": `${a.name}: 3D view` }, el("div", { class: "viewer-full-head" }, el("strong", {}, a.name), el("span", { class: "hint" }, hint || ""), close), stage); const view = viewer.getView(); stage.append(viewer.element); document.body.append(layer); const pane = $("detail"); const spot = document.createComment("viewer"); box.before(spot); const toggle = el("button", { class: "panel-toggle", type: "button", "aria-label": "Hide details", title: "Hide details", "aria-controls": "detail-body" }, icon(PANEL_HIDE)); toggle.addEventListener("click", () => { const hidden = pane.classList.toggle("panel-hidden"); toggle.replaceChildren(icon(hidden ? PANEL_SHOW : PANEL_HIDE)); toggle.setAttribute("aria-label", hidden ? "Show details" : "Hide details"); toggle.title = hidden ? "Show details" : "Hide details"; }); const stage = el("div", { class: "detail-stage" }, box, toggle); pane.prepend(stage); pane.classList.add("expanded"); document.documentElement.classList.add("viewer-open"); expanded = { layer, box, view }; requestAnimationFrame(() => viewer.fit()); // after the layer has its size close.focus(); expanded = { box, view: viewer.getView(), spot, stage }; setExpandButton(box, true); requestAnimationFrame(() => viewer.fit()); // after the stage has its size}function collapseViewer() { if (!expanded) return; const { layer, box, view } = expanded; const { box, view, spot, stage } = expanded; expanded = null; if (box.isConnected) { box.prepend(viewer.element); const pane = $("detail"); pane.classList.remove("expanded", "panel-hidden"); document.documentElement.classList.remove("viewer-open"); if (spot.isConnected) spot.replaceWith(box); stage.remove(); setExpandButton(box, false); if (viewer && box.isConnected) { viewer.resize(); viewer.setView(view); // the panel gets back the camera it had viewer.setView(view); box.querySelector(".viewer-expand")?.focus(); } layer.remove(); document.documentElement.classList.remove("viewer-open"); box.querySelector(".viewer-expand")?.focus();}
// Fallback when the 3D view can't run: the package thumbnail.111 unmodified lines if (state.asset !== a.id) return; box.prepend(v.element); v.resize(); const hint = bar.querySelector(".hint")?.textContent; box.append(el("button", { class: "viewer-expand", type: "button", "aria-label": "Expand 3D view", title: "Expand", onclick: () => expandViewer(a, box, hint) }, icon(EXPAND))); onclick: () => (expanded ? collapseViewer() : expandViewer(box)) }, icon(EXPAND))); let rig; if (loadedId === a.id && rigState.length) { rig = rigState.map((r) => ({ ...r }));7 unmodified lines8910111112131469 unmodified lines848586878788897 unmodified lines <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap"> <link rel="stylesheet" href="style.css?v=27"> <link rel="stylesheet" href="style.css?v=28"> <script type="importmap"> { "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",69 unmodified lines </aside> </div>
<script src="app.js?v=27"></script> <script src="app.js?v=28"></script></body></html>150 unmodified lines151152153154154155156157158159160161162163157158159160161162163164165166167168169170171172165173174175176177178179180181182183150 unmodified lines.viewer3d-toggle::after { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2.5px solid #f29b38; background: #1d1e20; opacity: 0; }.viewer3d-toggle[aria-pressed="true"]::after { opacity: 1; }.viewer3d-toggle:hover { border-color: #ffffff; }/* Expand button (top right, mirrors the dots toggle) and the full-window 3D view *//* Expand button (top right, mirrors the dots toggle) */.viewer-expand { position: absolute; top: 10px; right: 10px; z-index: 2; width: 28px; height: 28px; padding: 0; border-radius: 6px; border: 2px solid rgba(255, 255, 255, 0.75); background: rgba(20, 21, 23, 0.35); color: #fff; cursor: pointer; display: grid; place-items: center; }.viewer-expand:hover { border-color: #ffffff; background: rgba(20, 21, 23, 0.6); }.viewer-expand svg, .viewer-full-head svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }.viewer-full { position: fixed; inset: 0; z-index: 100; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 10px; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px)); background: rgba(10, 10, 11, 0.92); }.viewer-full-head { display: flex; align-items: center; gap: 12px; min-width: 0; color: #f3eee8; }.viewer-full-head strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.viewer-full-head .hint { flex: 1; min-width: 0; font-size: 12px; color: #a59d94; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.viewer-full-stage { min-height: 0; border-radius: var(--radius); overflow: hidden; border: 1px solid #3a3735; }.viewer-full-stage .viewer3d, .viewer-full-stage .viewer3d-stage { width: 100%; height: 100%; aspect-ratio: auto; }.viewer-expand svg, .panel-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Expanded view: the detail panel fills the window, 3D on the left, details on the right */.detail.expanded { position: fixed; inset: 0; z-index: 100; width: auto; box-shadow: none; border-left: 0; display: grid; grid-template-columns: minmax(0, 1fr) 440px; grid-template-rows: minmax(0, 1fr) auto; }.detail.expanded .detail-stage { grid-column: 1; grid-row: 1 / span 2; position: relative; min-width: 0; min-height: 0; padding: 16px; display: flex; background: var(--bg); }.detail.expanded .detail-stage .viewer { flex: 1; min-width: 0; display: flex; flex-direction: column; }.detail.expanded .detail-stage .viewer3d { flex: 1; min-height: 0; }.detail.expanded .detail-stage .viewer3d-stage { height: 100%; aspect-ratio: auto; }.detail.expanded #detail-body { grid-column: 2; grid-row: 1; border-left: 1px solid var(--line); }.detail.expanded #detail-foot { grid-column: 2; grid-row: 2; border-left: 1px solid var(--line); }.detail.expanded.panel-hidden { grid-template-columns: minmax(0, 1fr) 0; }.detail.expanded.panel-hidden #detail-body, .detail.expanded.panel-hidden #detail-foot { display: none; }.panel-toggle { display: none; }.detail.expanded .panel-toggle { display: grid; place-items: center; position: absolute; top: 50%; right: 0; transform: translateY(-50%); z-index: 3; width: 22px; height: 56px; padding: 0; border: 1px solid var(--line); border-right: 0; border-radius: 8px 0 0 8px; background: var(--raised); color: var(--muted); cursor: pointer; }.detail.expanded .panel-toggle:hover { color: var(--ink); }:root.viewer-open, :root.viewer-open body { overflow: hidden; }@media (max-width: 600px) { .viewer-full-head .hint { display: none; } }@media (max-width: 900px) { .detail.expanded { grid-template-columns: minmax(0, 1fr); grid-template-rows: 55vh minmax(0, 1fr) auto; } .detail.expanded .detail-stage { grid-row: 1; padding: 8px; } .detail.expanded #detail-body { grid-column: 1; grid-row: 2; border-left: 0; border-top: 1px solid var(--line); } .detail.expanded #detail-foot { grid-column: 1; grid-row: 3; border-left: 0; } .detail.expanded.panel-hidden { grid-template-rows: minmax(0, 1fr) 0 0; } .detail.expanded .panel-toggle { top: auto; bottom: 0; right: 50%; transform: translateX(50%) rotate(90deg); }}.viewer3d-status { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; font-size: 13px; color: var(--muted); pointer-events: none; }.joints { display: grid; gap: 8px; }.joint { display: grid; gap: 2px; }app.js+44-26
index.html+2-2
style.css+24-9