()
| 39 | type StoreMode = 'local' | `server:${string}`; |
| 40 | |
| 41 | function detectInitialMode(): StoreMode { |
| 42 | try { |
| 43 | const serverUrl = new URLSearchParams(window.location.search).get('server'); |
| 44 | if (serverUrl) { |
| 45 | new URL(serverUrl); // validate |
| 46 | return `server:${serverUrl}`; |
| 47 | } |
| 48 | } catch { |
| 49 | /* invalid URL or SSR / non-browser */ |
| 50 | } |
| 51 | return 'local'; |
| 52 | } |
| 53 | |
| 54 | function createStoreForMode(mode: StoreMode): GraphStore { |
| 55 | if (mode.startsWith('server:')) { |