1. The Problem
Linear document feeds collapse parallel reading branches into vertical scroll history, while browser canvas tools routinely trap state in server databases or block the main UI thread during pointer pan and zoom redraws.
SPATIAL HYPERMEDIA WORKBENCH · OFFSCREENCANVAS + POINTER EVENTS
Hypothesis: Mapping branching research graphs onto a URL-addressed
#cam=x,y,z&g=... 2D canvas (OffscreenCanvas + frustum
culling) preserves parallel exploration context better than linear chat scrollback while
staying bookmarkable with zero backend database state.
Linear chat logs bury branching explorations and parallel comparisons under vertical scrollback, while server-backed whiteboards break URL shareability.
Confirm: panning, zooming, and branching serialize deterministically into shareable #cam= URL hashes that restore identical state. Falsify: <canvas> degrades keyboard and screen-reader access unless paired with a synchronized DOM node tree (#node-directory-list).
Drag cards or pan the canvas, click + Add Research Card or Branch From Card, then click Verify Hash Round-Trip or Copy Snapshot URL to confirm deterministic state restoration.
Pointer drag pans canvas or moves hit-tested cards; wheel zooms under cursor; arrow keys pan when canvas has keyboard focus.
Load the three hypermedia presets served by /api/seed-graphs and observe
camera framing, edges, and node layouts update immediately.
Drag empty canvas to pan, drag any card to reposition it, or trigger a sample camera
pan to inspect live #cam=x,y,z&g=... URL synchronization.
Append a connected branch card to the graph, verify it renders inside the Worker, and copy the deterministic snapshot URL to clipboard.
Linear document feeds collapse parallel reading branches into vertical scroll history, while browser canvas tools routinely trap state in server databases or block the main UI thread during pointer pan and zoom redraws.
Make every spatial workspace state a self-contained, shareable URL hash snapshot
(#cam=x,y,z&g=...) with Worker-thread rasterization, a mirrored
semantic DOM index, and embeddable frame-ancestors headers.
Pointer Events map screen coordinates into world space via screenToWorld(),
computeVisibleViewportCount() culls offscreen cards,
canvas-renderer.js paints inside a Web Worker, and
history.replaceState() keeps the Base64URL hash synchronized.
Replacing linear append-only DOM chat logs and server workspace databases with a Worker-driven OffscreenCanvas 2D graph whose camera coordinates and branching nodes serialize deterministically into #cam= URL hashes.
// Linear append-only DOM list + backend DB persistence for every branch note
const msgEl = document.createElement("article");
msgEl.textContent = branchNote.summary;
chatTranscriptEl.appendChild(msgEl);
// Restoring or sharing branch state requires server IDs & database round-trips:
await fetch("/api/threads/" + threadId + "/nodes", {
method: "POST",
body: JSON.stringify({ parentId, x, y, summary: branchNote.summary }),
});
import { createBranchNode, encodeStateToHash, decodeStateFromHash }
from "./lib/canvas-state.js";
// Branch in client memory; serialize camera + graph directly into URL hash
const next = createBranchNode({ nodes, edges, camera, parentNodeId: selectedId });
const hash = encodeStateToHash({ camera, nodes: next.nodes, edges: next.edges });
history.replaceState(null, "", hash); // #cam=0,10,0.86&g=eyJub2RlcyI6...
// Copied URL restores exact camera + node graph with zero backend state:
const restored = decodeStateFromHash(window.location.hash);
End-to-end wiring from public/index.html, public/lib/canvas-state.js, public/app.js, and public/canvas-renderer.js: the page binds a <canvas> element, transfers presentation control to a Dedicated Module Worker via transferControlToOffscreen(), mirrors nodes in #node-directory-list for keyboard/screen-reader accessibility, and encodes camera and node-edge snapshots into #cam=x,y,z&g=... URL fragments.
<!-- 1. Page HTML Setup (public/index.html) -->
<div class="canvas-stage" id="canvas-stage">
<canvas id="spatial-canvas" tabindex="0" aria-label="Spatial hypermedia research canvas."></canvas>
</div>
<ul id="node-directory-list" class="node-directory"></ul>
<script type="module" src="/app.js"></script>
// 2. Concrete Seed Graph Definition & #cam= Hash Serializer (public/lib/canvas-state.js)
export function encodeStateToHash({ camera, nodes, edges }) {
const normCamera = normalizeCamera(camera);
const payload = JSON.stringify({
nodes: nodes.map(normalizeNode).filter(Boolean),
edges: edges.map(normalizeEdge).filter(Boolean),
});
return `#cam=${normCamera.x},${normCamera.y},${normCamera.zoom}&g=${base64UrlEncodeUtf8(payload)}`;
}
// 3. OffscreenCanvas Worker Wiring (public/app.js & public/canvas-renderer.js)
const offscreen = canvasEl.transferControlToOffscreen();
const renderWorker = new Worker("/canvas-renderer.js", { type: "module" });
renderWorker.postMessage({ type: "init", canvas: offscreen, width, height, dpr }, [offscreen]);
renderWorker.postMessage({ type: "render", scene: { camera, nodes, edges, selectedId } });
// Inside public/canvas-renderer.js:
self.addEventListener("message", (event) => {
if (event.data?.type === "init") {
offscreenCanvas = event.data.canvas;
ctx = offscreenCanvas.getContext("2d", { alpha: false });
}
if (event.data?.type === "render") {
pendingScene = event.data.scene;
requestRender();
}
});
// public/canvas-renderer.js — off-main-thread 2D paint + frustum metrics
const metrics = drawSpatialScene(ctx, { ...pendingScene, viewport });
self.postMessage({ type: "metrics", metrics });
// src/worker.ts — embeddable CSP + no-cache static headers (no COEP require-corp)
headers.set("Cache-Control", "no-cache");
headers.set("Content-Security-Policy", DOCUMENT_CSP); // permits https://aifoc.us frame-ancestors
headers.delete("Cross-Origin-Embedder-Policy");
headers.delete("X-Frame-Options");
Linear chat DOM lists that collapse branching structure, per-note server database writes, and main-thread 2D paint blocking during pointer pan and zoom.
World/screen transforms (worldToScreen(), screenToWorld()), frustum culling metrics, transferControlToOffscreen() Worker boundaries, and Base64URL #cam=x,y,z&g=... URL snapshots.
URL fragment length caps constrain large graphs without compression or OPFS storage, OffscreenCanvas pixels expose no DOM semantics without a mirrored tree (#node-directory-list), and transferControlToOffscreen() permanently binds one canvas element to its worker.