diff --git a/js/router.js b/js/router.js index f59508b..82c8820 100644 --- a/js/router.js +++ b/js/router.js @@ -59,6 +59,45 @@ const Router = (() => { return /^0x[a-fA-F0-9]{40}$/.test(address); } + // ─── View Nav Styles (injected once) ──────────────────────── + let stylesInjected = false; + function injectViewNavStyles() { + if (stylesInjected) return; + stylesInjected = true; + const style = document.createElement('style'); + style.textContent = ` + .view-nav { + display: flex; justify-content: center; gap: 4px; margin-top: 12px; + } + .view-tab { + padding: 8px 16px; border-radius: 8px 8px 0 0; + border: 1px solid rgba(255,255,255,0.08); border-bottom: 2px solid transparent; + background: rgba(255,255,255,0.02); color: #888; + text-decoration: none; font-size: 0.85rem; font-weight: 500; + transition: all 0.2s; display: flex; align-items: center; gap: 6px; + white-space: nowrap; + } + .view-tab:hover { background: rgba(255,255,255,0.06); color: #ccc; } + .view-tab.active { + border-bottom-color: #00d4ff; color: #00d4ff; + background: rgba(0,212,255,0.08); + } + .view-icon { font-size: 1rem; } + @media (max-width: 640px) { + .view-nav { gap: 2px; } + .view-tab { padding: 6px 10px; font-size: 0.75rem; } + } + `; + document.head.appendChild(style); + } + + // ─── View Definitions ─────────────────────────────────────── + const VIEWS = [ + { page: 'wallet-multichain-visualization.html', label: 'Multi-Chain Flow', icon: '⇄' }, + { page: 'wallet-timeline-visualization.html', label: 'Balance River', icon: '≈' }, + { page: 'wallet-visualization.html', label: 'Single-Chain Sankey', icon: '☰' }, + ]; + /** * Create a standard wallet address input bar for visualization pages. * Returns the input element for event binding. @@ -68,6 +107,20 @@ const Router = (() => { const container = document.getElementById(containerId); if (!container) return null; + injectViewNavStyles(); + + // Detect current page for active tab + const currentPage = window.location.pathname.split('/').pop() || 'index.html'; + + // Build view nav tabs + const viewTabs = VIEWS.map(v => { + const isActive = currentPage === v.page; + const href = buildUrl(v.page, address, getParams().chain, getParams().chainId); + return ` + ${v.icon} ${v.label} + `; + }).join(''); + container.innerHTML = `
@@ -79,6 +132,7 @@ const Router = (() => { value="${address}" spellcheck="false" autocomplete="off" />
+
${viewTabs}
`; @@ -93,6 +147,10 @@ const Router = (() => { return; } updateParams({ address: addr }); + // Update nav tab hrefs with new address + container.querySelectorAll('.view-tab').forEach((tab, i) => { + tab.href = buildUrl(VIEWS[i].page, addr, getParams().chain, getParams().chainId); + }); // Dispatch custom event for the page to handle window.dispatchEvent(new CustomEvent('wallet-changed', { detail: { address: addr } })); } diff --git a/wallet-multichain-visualization.html b/wallet-multichain-visualization.html index 5f0e3b6..0acc8cd 100644 --- a/wallet-multichain-visualization.html +++ b/wallet-multichain-visualization.html @@ -7,7 +7,7 @@ - +