SPATIAL HYPERMEDIA WORKBENCH · OFFSCREENCANVAS + POINTER EVENTS

Spatial Canvas OS

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.

Why this exists

Linear chat logs bury branching explorations and parallel comparisons under vertical scrollback, while server-backed whiteboards break URL shareability.

Confirm vs. falsify

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).

What to try first

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.

Interactive Canvas Workbench

Pointer drag pans canvas or moves hit-tested cards; wheel zooms under cursor; arrow keys pan when canvas has keyboard focus.

Initializing spatial canvas renderer...
Spatial Canvas OS requires HTML5 Canvas support. Use the accessible node directory panel beside this element to inspect and edit graph nodes.
cam(0, 0, 1.000) visible 0/0 0.00ms init
1. Switch Seed Graph

Load the three hypermedia presets served by /api/seed-graphs and observe camera framing, edges, and node layouts update immediately.

2. Pan/Drag Cards & Watch #cam= Hash Update

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.

3. Add Branch Node & Copy Shareable Snapshot Hash

Append a connected branch card to the graph, verify it renders inside the Worker, and copy the deterministic snapshot URL to clipboard.

Code & HTTP Wire Inspector

Live Deterministic Codec · Offscreen Telemetry · Edge Headers
#cam= Hash URL Codec 0 bytes
Deterministic Base64URL Hash State URL-safe

            
Canvas / OffscreenCanvas Telemetry frustum 0/0
Worker Message & Frustum Culling Metrics detecting

            
JSON Node Graph & Edge HTTP Headers GET /api/seed-graphs
Live Snapshot JSON & Observed Worker HTTP Headers HTTP 200

            

Runtime Boundary Diagram

Main Thread ⇄ Web Worker ⇄ Edge Origin
Spatial Canvas OS Runtime Architecture Four-stage pipeline: Pointer Events and history.replaceState on the main thread feed pure spatial codec transforms in canvas-state.js, which transfers an OffscreenCanvas to canvas-renderer.js in a Web Worker while Cloudflare Worker src/worker.ts serves /api/seed-graphs, no-cache static headers, and frame-ancestors CSP without COEP require-corp. 1. MAIN THREAD INPUT Pointer Events + DOM setPointerCapture() touch-action: none history.replaceState() #cam=x,y,z&g=Base64URL 2. PURE SPATIAL CODEC public/lib/canvas-state.js screenToWorld / worldToScreen hitTestNode(nodes, wx, wy) computeVisibleViewportCount() encodeStateToHash / decode 3. OFFSCREEN WORKER public/canvas-renderer.js transferControlToOffscreen() rAF coalesced scene draw Frustum culling + 2D cards Fallback: main-thread 2D 4. EDGE WORKER src/worker.ts GET /api/seed-graphs frame-ancestors aifoc.us No COEP require-corp Cache-Control: no-cache

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.

2. The Goal

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.

3. How It Works

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.

How This Is Set Up

What You Actually Write With This Pattern

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.

Today's pattern (the friction)
// 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 }),
});
With this pattern (what you author)
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);
Complete Page Setup: Real Definition, HTML Markup & Wiring

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();
  }
});
Core Plumbing Required Today (Browser + Edge / Protocol Contract)
// 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");
What disappears

Linear chat DOM lists that collapse branching structure, per-note server database writes, and main-thread 2D paint blocking during pointer pan and zoom.

What becomes explicit

World/screen transforms (worldToScreen(), screenToWorld()), frustum culling metrics, transferControlToOffscreen() Worker boundaries, and Base64URL #cam=x,y,z&g=... URL snapshots.

Platform gaps remaining

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.