diff --git a/web/src/main.ts b/web/src/main.ts index 3184763..f6b21b5 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -72,13 +72,16 @@ const content = document.createElement("section"); content.className = "content"; // Mobile (issue #35): the sidebar is an off-canvas drawer toggled by the ☰ in -// the tab bar; a backdrop covers the content while it's open, and tapping a +// the header; a backdrop covers the content while it's open, and tapping a // session closes it. On desktop these are inert (CSS gates the drawer styling). const backdrop = document.createElement("div"); backdrop.className = "mv-backdrop"; function closeDrawer(): void { shellEl.classList.remove("drawer-open"); } +function openDrawer(): void { + shellEl.classList.add("drawer-open"); +} function toggleDrawer(): void { shellEl.classList.toggle("drawer-open"); } @@ -87,6 +90,43 @@ sidebar.el.addEventListener("click", (e) => { if ((e.target as HTMLElement).closest(".tree-leaf")) closeDrawer(); }); +// Mobile: horizontal swipes drive the drawer (right opens, left closes) rather +// than the browser's back/forward navigation. We only act on a clearly +// horizontal gesture past a threshold, so vertical terminal scrolling (which +// owns its own touch handler) is untouched. +{ + const mobileMq = window.matchMedia("(max-width: 859px)"); + let sx = 0; + let sy = 0; + let tracking = false; + document.addEventListener( + "touchstart", + (e) => { + tracking = mobileMq.matches && e.touches.length === 1; + if (tracking) { + sx = e.touches[0].clientX; + sy = e.touches[0].clientY; + } + }, + { passive: true }, + ); + document.addEventListener( + "touchend", + (e) => { + if (!tracking) return; + tracking = false; + const t = e.changedTouches[0]; + const dx = t.clientX - sx; + const dy = t.clientY - sy; + if (Math.abs(dx) < 60 || Math.abs(dx) < Math.abs(dy) * 1.5) return; + const open = shellEl.classList.contains("drawer-open"); + if (dx > 0 && !open) openDrawer(); + else if (dx < 0 && open) closeDrawer(); + }, + { passive: true }, + ); +} + shellEl.append(sidebar.el, content, backdrop); root.replaceChildren(renderTopbar(store, toggleDrawer), shellEl);