Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.
fix(gallery): collapse navigation when preview is clicked (#361)
Dipras0482b93fc796
diff --git a/README.md b/README.mdindex fbde28c..73827f8 100644--- a/README.md+++ b/README.md@@ -308,7 +308,7 @@ Exploded axonometric draws one object in 2:1 dimetric projection with its partsAxonometric plan uses the same projection for one floor or one site: walls cut at desk height so every room reads from a single view, or buildings on a campus tagged by build phase. See the [office floor](skills/diagram-design/assets/example-axonometric-plan.html), the [campus](skills/diagram-design/assets/example-axonometric-plan-campus.html), the [coffee shop](skills/diagram-design/assets/example-axonometric-plan-coffee-shop.html), the [fulfillment floor](skills/diagram-design/assets/example-axonometric-plan-warehouse.html), the [phased campus animation](skills/diagram-design/assets/example-axonometric-plan-campus-animated.html), and the [reference](skills/diagram-design/references/type-axonometric-plan.md).-**Browse the live gallery:** [cathrynlavery.github.io/diagram-design](https://cathrynlavery.github.io/diagram-design/), or open [`skills/diagram-design/assets/index.html`](skills/diagram-design/assets/index.html) locally to flip through every diagram with light / dark / full-editorial tabs. Each type has one number, 01 to 44; its variants and worked examples carry the same number with a letter.+**Browse the live gallery:** [cathrynlavery.github.io/diagram-design](https://cathrynlavery.github.io/diagram-design/), or open [`skills/diagram-design/assets/index.html`](skills/diagram-design/assets/index.html) locally to flip through every diagram with light / dark / full-editorial tabs. Each type has one number, 01 to 44; its variants and worked examples carry the same number with a letter. The searchable diagram navigation starts open; click the preview to collapse it and use **Diagrams** to reopen it. The active diagram name and variant controls stay visible.---diff --git a/scripts/lint-render.py b/scripts/lint-render.pyindex 94fe5b9..1e425c9 100755--- a/scripts/lint-render.py+++ b/scripts/lint-render.py@@ -721,6 +721,137 @@ def gallery_mobile_failures(context, gallery_path=None):return failures+def gallery_navigation_failures(context):+ """Exercise shipped gallery interactions over HTTP and opaque local-file origins."""+ from playwright.sync_api import expect++ failures = []+ for mode in ("http", "file"):+ for viewport in ({"width": 1600, "height": 1000}, {"width": 390, "height": 844}):+ page = context.new_page()+ page.set_viewport_size(viewport)+ phase = "initial-state"+ label = f"gallery-navigation-{mode}-{viewport['width']}"+ runtime_errors = []+ page.on("pageerror", lambda error: runtime_errors.append(str(error)))+ try:+ if mode == "http":+ # Fulfill only committed HTML assets in memory. No listener or+ # network exception is needed under the linter's isolation policy.+ def serve_gallery(route):+ name = urlparse(route.request.url).path.removeprefix("/")+ asset = ASSET_DIR / name+ if "/" in name or not name.endswith(".html") or not asset.is_file():+ route.abort()+ return+ route.fulfill(content_type="text/html", body=asset.read_bytes())++ page.route("http://gallery.test/*", serve_gallery)+ url = "http://gallery.test/index.html"+ else:+ url = (ASSET_DIR / "index.html").as_uri()+ page.goto(url, wait_until="load")+ nav = page.locator("#diagram-nav")+ toggle = page.locator("#nav-toggle")+ search = page.locator("#diagram-search")+ preview = page.locator("#preview")+ expect(nav).to_be_visible()+ expect(toggle).to_have_attribute("aria-expanded", "true")+ expanded_height = preview.bounding_box()["height"]+ # Confirm file:// actually exercises the inaccessible-document fallback.+ accessible = page.evaluate("document.querySelector('#preview').contentDocument !== null")+ assert accessible == (mode == "http"), "unexpected iframe origin accessibility"++ phase = "preview-collapse-and-reopen"+ for attempt in range(3):+ page.frame_locator("#preview").locator("body").click(position={"x": 24, "y": 24})+ expect(nav).to_be_hidden()+ expect(toggle).to_have_attribute("aria-expanded", "false")+ assert preview.bounding_box()["height"] > expanded_height, "collapse did not enlarge preview"+ expect(page.locator("#current-diagram")).to_be_visible()+ expect(page.locator("#variant-tabs")).to_be_visible()+ if mode == "http" and attempt == 0:+ # Retain iframe focus on reopen: the next click must be+ # handled by its pointer listener, not another window blur.+ toggle.evaluate("button => button.click()")+ assert page.evaluate("document.activeElement === document.querySelector('#preview')")+ else:+ toggle.click()+ expect(nav).to_be_visible()+ expect(toggle).to_have_attribute("aria-expanded", "true")++ phase = "filtered-keyboard-navigation"+ search.fill("scatter")+ visible = page.locator("#type-tabs .tab:visible")+ names = visible.evaluate_all("tabs => tabs.map(tab => tab.dataset.type)")+ assert len(names) >= 3, "scatter filter did not expose related variants"+ expect(page.locator('#type-tabs .tab.active')).to_be_hidden()+ search.press("Tab")+ expect(visible.first).to_be_focused()+ for key, expected in (("ArrowRight", names[1]), ("ArrowLeft", names[0]),+ ("ArrowLeft", names[-1]), ("ArrowRight", names[0])):+ page.keyboard.press(key)+ selected = page.locator(f'#type-tabs [data-type="{expected}"]')+ expect(selected).to_be_focused()+ expect(selected).to_have_attribute("aria-checked", "true")+ expect(preview).to_have_attribute("src", f"example-{expected}.html")++ phase = "empty-search-and-recovery"+ search.fill("no-matching-diagram-xyz")+ expect(visible).to_have_count(0)+ expect(page.locator("#empty-results")).to_be_visible()+ search.fill("polar")+ expect(page.locator("#empty-results")).to_be_hidden()+ expect(visible).to_have_count(1)+ with page.expect_event(+ "framenavigated",+ predicate=lambda frame: frame.parent_frame == page.main_frame+ and frame.url.endswith("/example-polar.html"),+ ):+ visible.first.click()+ expect(preview).to_have_attribute("src", "example-polar.html")+ search.fill("")+ expect(visible).to_have_count(page.locator("#type-tabs .tab").count())+ expect(page.locator('#type-tabs [data-type="polar"]')).to_have_attribute("aria-checked", "true")++ phase = "collapse-after-example-change"+ page.frame_locator("#preview").locator("body").click(position={"x": 24, "y": 24})+ expect(nav).to_be_hidden()+ toggle.click()+ search.focus()+ search.press("Escape")+ expect(nav).to_be_hidden()+ expect(toggle).to_be_focused()++ phase = "first-click-inside-preview"+ # Collapsing must not move the preview between press and release,+ # or the first click on a control inside the example is lost.+ # A tall window keeps the playback controls on screen without scrolling.+ page.set_viewport_size({"width": viewport["width"], "height": 1400})+ toggle.click()+ search.fill("fan-in")+ expect(visible).to_have_count(1)+ visible.first.click()+ expect(preview).to_have_attribute("src", "example-queue-animated.html")+ play = page.frame_locator("#preview").locator('[data-motion-action="play"]')+ expect(play).to_have_attribute("aria-pressed", "false")+ expect(play).to_be_in_viewport()+ expect(nav).to_be_visible()+ box = play.bounding_box()+ page.mouse.move(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)+ page.mouse.down()+ page.wait_for_timeout(120)+ page.mouse.up()+ expect(play).to_have_attribute("aria-pressed", "true")+ expect(nav).to_be_hidden()+ assert not runtime_errors, "; ".join(runtime_errors)+ except Exception as error:+ failures.append(f"{label}-{phase}: {str(error).splitlines()[0]}")+ finally:+ page.close()+ return failures++def waterfall_mobile_failures(context, waterfall_paths=None):"""Keep waterfall labels readable while containing its wide plot locally."""paths = waterfall_paths or sorted(ASSET_DIR.glob("example-waterfall*.html"))@@ -1236,6 +1367,10 @@ def self_test(context):checks += 1failures += gallery_mobile_failures(context)+ # Same-origin iframe clicks and file:// focus fallback, desktop and mobile.+ checks += 4+ failures += gallery_navigation_failures(context)+# The waterfall uses 8px SVG labels, so shrinking its 1000-unit canvas to# a phone width is not a responsive layout. Keep it readable and scroll it# inside a local container without widening the document.diff --git a/skills/diagram-design/assets/index.html b/skills/diagram-design/assets/index.htmlindex 07284fd..205e637 100644--- a/skills/diagram-design/assets/index.html+++ b/skills/diagram-design/assets/index.html@@ -43,15 +43,15 @@}.topbar {- padding: 1rem 1.25rem 0.625rem;+ padding: 0.875rem 1.25rem;border-bottom: 1px solid var(--rule);flex: 0 0 auto;}.title-row {display: flex;- align-items: baseline;+ align-items: center;justify-content: space-between;- margin-bottom: 0.75rem;+ margin-bottom: 0.625rem;gap: 1rem;}.title-row h1 {@@ -63,14 +63,14 @@}.title-row .meta {font-family: var(--mono);- font-size: 0.66rem;+ font-size: 0.75rem;letter-spacing: 0.18em;text-transform: uppercase;color: var(--muted);}.title-row .open-raw {font-family: var(--mono);- font-size: 0.66rem;+ font-size: 0.75rem;letter-spacing: 0.06em;color: var(--muted);text-decoration: none;@@ -94,8 +94,11 @@}.tabs.variants {margin-bottom: 0;- padding-top: 0.5rem;- border-top: 1px solid var(--rule);+ padding: 0;+ border: 0;+ flex-wrap: nowrap;+ flex: 0 1 auto;+ gap: 0.25rem;}.tab {font-family: var(--sans);@@ -127,7 +130,7 @@display: inline-block;margin-right: 0.25rem;font-family: var(--mono);- font-size: 0.56rem;+ font-size: 0.6875rem;letter-spacing: 0.12em;text-transform: uppercase;color: inherit;@@ -138,7 +141,7 @@display: inline-block;margin-left: 0.35rem;font-family: var(--mono);- font-size: 0.54rem;+ font-size: 0.6875rem;letter-spacing: 0.12em;color: var(--accent);vertical-align: 1px;@@ -163,36 +166,87 @@display: block;}+ [hidden] { display: none !important; }+ main { min-height: 0; }+ .brand, .header-actions, .controls, .catalog-tools {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ min-width: 0;+ }+ .header-actions { gap: 0.5rem; }+ .nav-toggle { display: inline-flex; align-items: center; gap: 0.5rem; flex: 0 0 auto; }+ .nav-toggle svg { width: 16px; height: 16px; }+ .nav-toggle[aria-expanded="true"] { background: var(--paper-2); color: var(--ink); }+ .controls { justify-content: space-between; gap: 1rem; }+ .current-diagram { font-size: 0.8125rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+ .catalog { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--rule); }+ .catalog-tools { justify-content: space-between; margin-bottom: 0.625rem; }+ .search-label { display: flex; align-items: center; gap: 0.625rem; font-size: 0.75rem; min-width: 0; }+ #diagram-search {+ width: min(20rem, 45vw);+ padding: 0.5rem 0.625rem;+ border: 1px solid var(--rule-strong);+ border-radius: 4px;+ background: transparent;+ font: 0.8125rem var(--sans);+ color: var(--ink);+ caret-color: var(--accent);+ }+ #diagram-search::placeholder { color: var(--muted); }+ .catalog-hint, .empty-results { font-size: 0.75rem; color: var(--muted); }+ #type-tabs {+ max-height: min(10rem, 22vh);+ overflow-y: auto;+ overscroll-behavior: contain;+ scrollbar-width: thin;+ scrollbar-color: var(--rule-strong) var(--paper);+ margin: 0;+ padding: 2px 0.5rem 2px 2px;+ }+ #type-tabs .tab { text-align: left; max-width: 100%; overflow-wrap: anywhere; }+ .empty-results { padding: 0.75rem 0; }+ :is(button, a, input):focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }+ ::selection { background: var(--ink); color: var(--paper); }@media (max-width: 640px) {- #type-tabs {- flex-wrap: nowrap;- overflow-x: auto;- overscroll-behavior-inline: contain;- padding-bottom: 0.25rem;- scrollbar-width: thin;- }- #type-tabs .tab {- flex: 0 0 auto;- }+ .topbar { padding: 0.75rem; }+ .title-row { flex-wrap: wrap; gap: 0.625rem; }+ .brand { flex: 1 1 auto; }+ .title-row h1 { font-size: 1.35rem; }+ .title-row .meta { display: none; }+ .header-actions { margin-left: auto; }+ .controls { flex-wrap: wrap; gap: 0.5rem; }+ .current-diagram { flex-basis: 100%; }+ .tabs.variants { flex-wrap: wrap; max-width: 100%; }+ .catalog-hint { display: none; }+ .search-label { width: 100%; }+ #diagram-search { flex: 1; width: 0; }+ #type-tabs { max-height: min(8rem, 18vh); }}</style></head><body><header class="topbar"><div class="title-row">+ <div class="brand">+ <button class="tab nav-toggle" id="nav-toggle" type="button" aria-expanded="true" aria-controls="diagram-nav">+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h16"/></svg>+ Diagrams+ </button><h1>Diagram Design<spanclass="meta"style="font-family: var(--mono);- font-size: 0.66rem;+ font-size: 0.75rem;margin-left: 0.5rem;">· gallery</span></h1>- <div style="display: flex; gap: 0.5rem">+ </div>+ <div class="header-actions"><a class="open-raw" href="icons.html" target="_blank" rel="noopener">icon library ↗</a>@@ -207,6 +261,26 @@</div></div>+ <div class="controls">+ <p class="current-diagram" id="current-diagram">Architecture</p>+ <div+ class="tabs variants"+ id="variant-tabs"+ role="radiogroup"+ aria-label="Variant"+ >+ <button class="tab active" data-variant="">Minimal light</button>+ <button class="tab" data-variant="-dark">Minimal dark</button>+ <button class="tab" data-variant="-full">Full editorial</button>+ </div>+ </div>+ <nav class="catalog" id="diagram-nav" aria-label="Diagram catalog">+ <div class="catalog-tools">+ <label class="search-label" for="diagram-search">Find a diagram+ <input id="diagram-search" type="search" placeholder="Search diagrams…" autocomplete="off" />+ </label>+ <span class="catalog-hint">Click the preview to hide navigation</span>+ </div><div class="tabs" id="type-tabs" role="radiogroup" aria-label="Diagram type"><button class="tab active" data-type="architecture"><span class="eyebrow">01</span>Architecture@@ -450,16 +524,8 @@</button></div>- <div- class="tabs variants"- id="variant-tabs"- role="radiogroup"- aria-label="Variant"- >- <button class="tab active" data-variant="">Minimal light</button>- <button class="tab" data-variant="-dark">Minimal dark</button>- <button class="tab" data-variant="-full">Full editorial</button>- </div>+ <p class="empty-results" id="empty-results" role="status" hidden>No diagrams found. Try another search.</p>+ </nav></header><main>@@ -475,10 +541,71 @@const iframe = document.getElementById("preview");const openRaw = document.getElementById("open-raw");+ const nav = document.getElementById("diagram-nav");+ const navToggle = document.getElementById("nav-toggle");+ const search = document.getElementById("diagram-search");+ const typeTabs = [...document.querySelectorAll("#type-tabs .tab")];+ const diagramName = (tab) => [...tab.childNodes]+ .filter((node) => node.nodeType === Node.TEXT_NODE)+ .map((node) => node.textContent).join("").trim();++ function setNavigation(open) {+ nav.hidden = !open;+ navToggle.setAttribute("aria-expanded", String(open));+ }+ navToggle.addEventListener("click", () => setNavigation(nav.hidden));+ nav.addEventListener("keydown", (event) => {+ if (event.key === "Escape") {+ setNavigation(false);+ navToggle.focus();+ }+ });+ function filterDiagrams() {+ const query = search.value.trim().toLowerCase();+ typeTabs.forEach((tab) => {+ tab.hidden = !diagramName(tab).toLowerCase().includes(query);+ });+ const visible = typeTabs.filter((tab) => !tab.hidden);+ // Keep one visible option reachable with Tab even if selection is filtered out.+ const focusable = visible.find((tab) => tab.dataset.type === state.type) || visible[0];+ typeTabs.forEach((tab) => { tab.tabIndex = tab === focusable ? 0 : -1; });+ document.getElementById("empty-results").hidden = visible.length > 0;+ }+ search.addEventListener("input", filterDiagrams);+ // Collapse on click, not pointerdown: hiding the catalog moves the preview+ // up, so collapsing mid-press would pull a control out from under the pointer+ // and its click would never fire.+ document.querySelector("main").addEventListener("click", () => setNavigation(false));+ iframe.addEventListener("load", () => {+ try {+ // Iframe events do not bubble to the gallery. Bind after each example load.+ iframe.contentDocument.addEventListener("click", () => setNavigation(false));+ } catch {+ // Local file previews may have an opaque origin; focus is handled below.+ }+ });+ // Opaque local previews expose only the focus change on press. Wait for a+ // normal click to finish inside the example before moving it.+ const PREVIEW_CLICK_GRACE_MS = 400;+ let blurCollapse = 0;+ window.addEventListener("blur", () => {+ if (document.activeElement !== iframe) return;+ let accessible = false;+ try { accessible = iframe.contentDocument !== null; } catch { accessible = false; }+ if (accessible) return;+ clearTimeout(blurCollapse);+ blurCollapse = setTimeout(() => {+ if (document.activeElement === iframe) setNavigation(false);+ }, PREVIEW_CLICK_GRACE_MS);+ });+function update() {const activeType = [...document.querySelectorAll("#type-tabs .tab")].find((tab) => tab.dataset.type === state.type,);+ const name = diagramName(activeType);+ document.getElementById("current-diagram").textContent = name;+ iframe.title = `${name} preview`;const single = activeType && activeType.hasAttribute("data-single");const variantTabs = document.querySelectorAll("#variant-tabs .tab");if (single) state.variant = "";@@ -499,10 +626,11 @@const src = `example-${state.type}${state.variant}.html`;iframe.src = src;openRaw.href = src;- const selectedTabs = document.querySelectorAll('[role="radio"][aria-checked="true"]');+ filterDiagrams();+ const selectedTabs = document.querySelectorAll('#variant-tabs [role="radio"][aria-checked="true"]');iframe.setAttribute("aria-labelledby",- [...selectedTabs].map((tab) => tab.id).join(" "),+ ["current-diagram", ...[...selectedTabs].map((tab) => tab.id)].join(" "),);}@@ -523,13 +651,13 @@container.addEventListener("click", (e) => {const btn = e.target.closest(".tab");- if (!btn) return;+ if (!btn || btn.disabled) return;activate(btn);});container.addEventListener("keydown", (e) => {const current = e.target.closest('[role="radio"]');if (!current || !container.contains(current)) return;- const enabledTabs = tabs.filter((tab) => !tab.disabled);+ const enabledTabs = tabs.filter((tab) => !tab.disabled && !tab.hidden);const index = enabledTabs.indexOf(current);let next;if (e.key === "ArrowRight" || e.key === "ArrowDown") {