Put thousands of live DOM nodes on an infinite canvas: the GPU draws them, an editor selects, moves and resizes them, shaders and transitions run on them, and an AI agent can read them and point at them.
The same session on both sides: 5,000 live React screens, the same camera path, a message typed and sent. Left, every screen is plain DOM under a CSS transform. Right, gpucanvas. Recorded in Chrome on a MacBook Pro; the frame rates are measured live in each run. Run it yourself in the live demo.
- Canvas. Live React or plain DOM nodes, drawn by WebGPU in one instanced pass. Pan and zoom never touch the DOM, and clicks, typing and state still reach the real elements.
- Editor. Click to select, double-click to go a layer deeper, down to any element or React component. Move and resize with snapping guides.
- Shader effects. Run WGSL on live components: a glass lens, frost, shockwaves, glitch, VHS, or your own.
- Snapshots. Any node as an image, pixel diffs between versions, and a filmstrip of its history.
- Agent view. What is on the canvas as a short JSON tree with ids, and an image of any region, for an AI agent to read and point at.
- Transitions. Dissolve, wipe or fade a node out and another in, on the GPU, while both stay live.
- Marks. Arrows between elements, comment pins, notes and live cursors that follow the camera.
Marks from an agent, a wipe and a dissolve, the glass lens and shockwaves, all on live components. Recorded in Chrome from the demo.
How it works, with the benchmarks and what Chrome's HTML-in-Canvas does differently from the explainer: gpucanvas: 5,000 Live React Screens on a WebGPU Infinite Canvas.
Open berkantay.github.io/gpucanvas in Chrome 157 or later. Thirty agent cursors build the first view, then the camera pulls out to all 5,000 screens.
- Click a screen to select it, double-click to go deeper, drag to move it. Double-click a text field to type in it, or switch the toolbar to Interact and use the screens like a normal page.
- In Interact, every button does something. Continue, Sign in and Back move the camera to the next screen like a clickable prototype, Notifications and More open panels, Export saves a CSV, Send adds the message and Share copies the link.
- The toolbar holds every setting: renderer, number of screens, Edit or Interact, what a click selects, the shader effect, the agent cursors and the theme. They apply live, and the URL remembers them.
- Pick a shader effect in the toolbar, or open one directly: glass, shockwave (click anywhere), frost, glitch.
- Select a screen and press
Dto dissolve it,Wto wipe it, orSto save it as a PNG. - In the console,
agentView.describe()lists what is in view, andmarksdraws on it. - Press
bto run the benchmark tour,fto fit every screen in view,tto switch the theme. - On a phone: pinch to zoom, drag to pan, tap to use a screen.
The GPU path needs WebGPU and HTML-in-Canvas. Chrome 157 and later on a computer has both on by
default, so the demo opens on the GPU path. On older Chrome or other Chromium builds, turn it on
with chrome://flags/#canvas-draw-element and relaunch.
Without HTML-in-Canvas the demo runs the DOM fallback with 1,000 screens and says so. Phones start smaller so the tab is not killed for memory: 1,000 screens on the GPU path and 250 as DOM. Firefox, Safari and every iPhone or iPad browser have no HTML-in-Canvas yet, so they run the DOM version and say so.
Status: early (0.6). The API can still change.
npm install gpucanvasimport { GpuCanvas, CanvasNode } from 'gpucanvas/react';
<GpuCanvas style={{ width: '100vw', height: '100vh' }}>
{cards.map((card) => (
<CanvasNode key={card.id} x={card.x} y={card.y} width={240} height={150}>
<Card {...card} />
</CanvasNode>
))}
</GpuCanvas>;Nodes stay real DOM: React state, events, CSS and accessibility work as usual. Where WebGPU and HTML-in-Canvas are available (Chrome 157+), nodes are snapshotted into a GPU atlas and drawn in one instanced draw call. Everywhere else it falls back to a CSS-transformed container with the same API.
bindEditor turns the canvas into an editor: select, drill in, move and resize. The GPU draws
the outlines, 2 CSS pixels wide at any zoom, and they follow their element's layout. Names,
sizes, handles and snapping guides sit in a thin overlay above it.
import { bindEditor } from 'gpucanvas';
const editor = bindEditor(canvas, {
pick: 'element', // 'node' (default), 'element', or a function
trigger: 'click', // an edit mode; the default 'shift-click' leaves clicks to your components
onChange: (layers) => console.log(layers),
onTransform: ({ phase, layers, to }) => {
// The editor never moves anything itself. Apply `to` with updateNode, state or styles.
},
});A click selects the outermost layer under the pointer, a whole node. Each double-click goes one layer deeper, and later clicks stay at that depth. Wrappers the size of their parent are skipped, so every double-click visibly changes something.
| Input | Does |
|---|---|
| Double-click | One layer deeper; on a text field, starts typing in it |
| Enter, Shift+Enter | First child, parent |
| Tab, Shift+Tab | Next and previous sibling |
| Escape | Ends typing, cancels a drag, then goes up a layer, then clears |
| Drag | Moves, snapping to the edges and centers of neighbors (Shift locks the axis) |
| Handles | Resize (Shift on a corner keeps the ratio) |
| Drag on open space | A box that selects the layers it touches, inside the layer you are in |
With the default trigger: 'shift-click', the same works with Shift held, and clicks still reach
your components. A layer is an array of elements, so one layer can be a component that renders
several. pick decides the layers:
'node': whole nodes only.'element': every element from the node down to the one under the pointer.- a function of that element, returning the layers that hold it, outermost first.
In React, useEditor gives the selection as state, and pickComponents makes the layers React
components:
import { labelComponent, pickComponents, useEditor } from 'gpucanvas/react';
// Inside <GpuCanvas>:
const { selected, clear } = useEditor({ pick: pickComponents, label: labelComponent });
// Click a screen, double-click: SignIn, SignInCard, Button.pickComponents and componentOf read React's internal fibers, as click-to-component tools do.
Production builds usually minify component names, so mark components with your own attributes
when you need names there.
The building blocks, for your own interactions:
canvas.getElementAt(point); // deepest element at a world point
canvas.getElementRect(el); // any element's rect in world units
canvas.getNodeOf(el); // the node that holds it
canvas.getNodes(); // every node, in the order they were added
canvas.getNodesIn(rect); // nodes overlapping a world rect
canvas.setSelection(elements); // outline these; [] clears
canvas.setHover(el); // a lighter outline; null clears
canvas.screenToWorld(point); // surface pixels to world units, and worldToScreen back
canvas.addCameraListener((camera) => {}); // every camera change; returns a function that stops it
createMarquee(canvas).update(a, b); // a selection box between two surface points; returns its world rectColors are the selectionColor and hoverColor options; the editor, marks and marquee follow
selectionColor unless given their own. In the demo, the toolbar switches between
Edit and Interact (clicks reach the components) and picks components, elements or whole screens.
Tab and Shift+Tab move through the fields of every node, in the order the nodes were added, and the camera pans just enough to show the field. Past the last node, Tab leaves the canvas.
Popups a component opens in document.body (Radix, floating-ui) open next to their button, since
a node under the pointer or holding focus reports where it is drawn from getBoundingClientRect.
The camera moves without scrolling anything, so tell the popup library when it does:
const stop = canvas.addCameraListener(() => popup.update()); // floating-ui: computePosition againposition: fixed inside a node is fixed to the node, on both backends.
Components stay live DOM, and the GPU draws them through a shader. One call per node:
import { effects } from 'gpucanvas';
canvas.setEffect(node, effects.ripple); // the effect's default parameters
canvas.setEffect(node, effects.glow, [1, 0.4, 0.2, 32]); // orange, 32 px reach
canvas.setEffect(node, null); // back to plainBuilt in:
- Following the pointer:
glass(a magnifying lens),frost(ice, clear around the pointer),dither(a lens of big dithered pixels). - On each press:
shockwave, a ring that bends the node as it spreads. - Running on their own:
glitch,vhs,glow,hue,ripple. - Still:
blur,pixelate,grayscale. - Transitions:
dissolve,wipeandfade, for a node leaving or arriving (the first parameter is the progress, 0 to 1).
Animated effects draw every frame while their node is in view; still ones cost nothing once drawn.
Your own is a WGSL function over the node's pixels:
import { defineEffect } from 'gpucanvas';
const scanlines = defineEffect({
name: 'scanlines',
animated: true,
params: [3], // line spacing in CSS pixels
wgsl: /* wgsl */ `
fn effect(input: EffectInput) -> vec4f {
let color = source(input.uv);
let y = input.uv.y * input.size.y + input.time * 20.0;
return color * (0.85 + 0.15 * step(0.5, fract(y / input.params.x)));
}`,
});EffectInput has uv (0 to 1 across the node), size in CSS pixels, time in seconds,
zoom, the four params, the pointer and the last press in the node's uv, and
sincePress in seconds. source(uv) reads the node's pixels, premultiplied, and is
transparent outside it; hash and noise give random values. An effect that draws past its
node, like a glow, declares how far with pad. Effects read the node's whole snapshot, so very
close in they are softer than plain nodes. In React, <CanvasNode effect={effects.glass}> does
the same.
The DOM backend shows effects that have a css look as a CSS filter (animated ones as filter
animations) and the rest as plain nodes. The demo's toolbar puts one effect on every component.
Every node is already drawn by the GPU, so its pixels are one call away, with no headless browser:
import { diffImages, recordFilmstrip, toBlob } from 'gpucanvas';
const before = await canvas.snapshot(node, { scale: 2 }); // ImageData, drawn fresh
const png = await toBlob(before); // a PNG Blob
// ...the screen changes...
const after = await canvas.snapshot(node, { scale: 2 });
const { changed, bounds, image } = diffImages(before, after); // what moved, and where
// A snapshot after every change, once it settles.
const strip = recordFilmstrip(canvas, node, { scale: 0.25, max: 30, onError: console.error });
strip.frames; // [{ at, image }, ...]
strip.stop();A snapshot is the node as it looks now, at any scale, whether or not it is in view. It takes a
paint or two, about 40 ms for a 1,500 by 1,000 pixel screen. In the demo, select a screen and
press S to save it.
The DOM backend cannot draw a node into an image itself, so there snapshot rejects unless you
give the canvas a snapshotFallback. Any DOM-to-image library fits; this one uses
SnapDOM, which the demo does too:
import { snapdom } from '@zumer/snapdom';
const canvas = await createGpuCanvas(host, {
async snapshotFallback(node, { scale }) {
// `scale` already counts the device pixel ratio, so dpr 1 keeps it from applying twice.
const drawn = await snapdom.toCanvas(node, { scale, dpr: 1 });
return drawn.getContext('2d')!.getImageData(0, 0, drawn.width, drawn.height);
},
});<GpuCanvas snapshotFallback={...}> takes the same function. Selection and hover outlines stay
out of the image on both backends. One difference: on the DOM backend an effect is a CSS filter
on the node, so a fallback snapshot includes it, while a GPU snapshot is the node without its
effect.
An agent reads the canvas the way a person sees it: what is there, what it says, and where:
import { createAgentView } from 'gpucanvas';
const view = createAgentView(canvas);
view.describe(); // what is in view, as JSON
// [{ id: 'e35', tag: 'div', rect: { x: -3552, y: -2561, width: 1496, height: 958 }, children: [
// { id: 'e6', tag: 'h1', role: 'heading', text: 'Welcome back', rect: { ... } },
// { id: 'e18', tag: 'input', role: 'textbox', name: 'Email', rect: { ... } },
// { id: 'e23', tag: 'input', role: 'checkbox', name: 'Keep me signed in', checked: true, ... },
// { id: 'e25', tag: 'button', role: 'button', text: 'Sign in', rect: { ... } }, ...] }]
view.element('e25'); // the element behind an id
await view.capture('e6', { scale: 2 }); // ImageData of that element
await view.capture({ x: 0, y: 0, width: 4000, height: 3000 }, { scale: 0.25 }); // any regionWrappers that add nothing are left out, so a sign-in screen is about 35 entries and 3.5 KB of
JSON, read in 3 ms. Pass rect to read another region and name to label elements with your
own names, such as their React component's. capture needs the GPU backend.
Any effect whose first parameter is progress (0 whole, 1 gone) animates as a transition:
dissolve, wipe and fade are built in.
import { animateEffect, effects, swapNodes } from 'gpucanvas';
await animateEffect(canvas, node, effects.wipe, { duration: 600, params: [90] }); // wipe downward
await animateEffect(canvas, node, effects.wipe, { from: 1, to: 0 }); // and back
// One screen burns away while the next appears in its place.
await swapNodes(canvas, oldScreen, newScreen, { effect: effects.dissolve, duration: 800 });
canvas.removeNode(oldScreen);A node that ends whole loses the effect; one that ends gone stays hidden until it is removed.
Starting another animation on a node replaces the running one, which resolves false. In the
demo, select a screen and press D to dissolve it or W to wipe it. The DOM backend fades.
Draw on top of the nodes. Marks follow the camera and the elements they are attached to, and stay the same size on screen at any zoom:
import { createMarks } from 'gpucanvas';
const marks = createMarks(canvas);
marks.connect(button, nextScreen, { label: 'goes to' }); // a curved arrow
marks.pin(card, { label: '3', text: 'Rename to Continue?', onClick: openThread });
marks.note(view.element('e6'), 'This heading is 2px off the grid'); // what an agent means
const cursor = marks.cursor('Ada', { color: '#e11d48' });
cursor.move({ x: 120, y: 80 }); // glides there, in world units
marks.clear();Arrows and pins also take a world point in place of an element. Marks are SVG and HTML in a
layer above the canvas, so they work with both backends. In the demo, both are on window:
agentView and marks.
bun install
bun run dev # http://localhost:5199/?mode=gpu&n=10000 (mode: auto | gpu | dom)Publishing a GitHub release for a vX.Y.Z tag that matches package.json publishes the package
to npm from GitHub Actions, with provenance, through npm trusted publishing. See
release.yml.
- Pages. Nodes are live DOM inside
<canvas content="drawable">, packed side by side into pages of 2048 CSS pixels. Chrome records a page as one snapshot, so onedrawElementImageToTexturecall rasterizes dozens of nodes at once. - Rasterize, then park. A page with nodes waiting for pixels becomes
drawable. In the next paint event it is drawn into a texture-array atlas, whole or one node at a time when only a few changed. Then it is parked withcontent-visibility: hidden, which keeps layout but skips paint, so the browser spends nothing on it per frame. - Thumbnails first. Every node gets a 1/16 scale thumbnail in an atlas layer that is never evicted, so a zoomed-out view of thousands of screens is always filled in. Sharper snapshots go on top at power-of-two scales, so zooming reuses them.
- Tiles up close. Past 100% zoom on a 2x display, only the visible part of a node is rasterized, as sharp tiles, center first. While its content animates, one half-resolution preview stands in.
- One draw call. Each frame culls nodes against the view and draws every visible one with one instanced quad draw, or one per run of nodes sharing a shader effect. Panning and zooming never touch the DOM. Raster work has a per-frame budget, so the camera stays smooth while pixels fill in.
- Live updates. A MutationObserver marks a node dirty when its content changes, and loading images, web fonts and CSS transitions trigger a redraw. Animated content on nodes under 200 screen pixels refreshes at most four times a second.
- Input. Only the page under the pointer is registered for hit testing, and its canvas transform puts the node under the pointer exactly where the GPU drew it. Clicks, typing, selection and hover all go to the real element. A focused node keeps its page live, lined up with its drawing when the pointer is elsewhere. Touch has no hover, so a tap makes the node under the finger live and hands the click to the element it landed on. A two-finger pinch zooms and pans the camera wherever the fingers land.
The demo's benchmark (press b) runs a 30-second tour: a message typed and sent, a chart
animating, a push to 500% zoom, shift-click picks and a selection sweep, while 30 agent cursors
build screens around the view. Every frame is timed. At 5,000 screens it measures 113 to 115 fps
for gpucanvas and 18 to 20 for DOM, and 138 for gpucanvas in the effects run below.
The table below was measured with the 0.1 benchmark, a 94-second session from the overview into clusters of app screens, close-ups up to 500% zoom, 20 clicks and typed messages, then back out.
| Screens | gpucanvas avg fps | gpucanvas p95 | DOM avg fps | DOM p95 | Mount gpucanvas / DOM |
|---|---|---|---|---|---|
| 5,000 | 117 | 9.2 ms | 23 | 50.2 ms | 1.2 s / 1.3 s |
| 10,000 | 108 | 16.7 ms | 9 | 133.8 ms | 1.8 s / 3.4 s |
DOM is the same screens in one CSS-transformed container, which is also the fallback backend.
Shader effects on every one of the 5,000 screens, the same 30-second tour, vsync off:
| Effect | gpucanvas avg fps | p95 |
|---|---|---|
| none | 138 | 15.2 ms |
| glow | 135 | 15.6 ms |
| blur (32 taps) | 138 | 16.7 ms |
| glass | 122 | 18.2 ms |
| frost | 146 | 13.8 ms |
Effects draw from each node's snapshot in the same pass, so most cost nothing measurable; glass, which samples around the pointer with a rim and shadow, costs about 12%. Each figure is one run, so a gap of a few percent, like frost above none, is noise rather than a speedup.
- Hit-test registration. A drawable is hit-tested only after
canvas.updateElementGeometry(el, options)registers it. - Hit-test position. Chrome 157 hit tests at
options.canvasTransform, a matrix in CSS pixels from the element's border box to the canvas, andgetElementTransform(el)returns it. Chrome 156 ignoredcanvasTransformand hit tested at the CSS box, positioned withel.style.transform = canvas.getElementTransform(el, drawMatrix). gpucanvas handles both. - Transform changes. Changing a drawable's CSS transform or pointer-events reports it in
changedElements. - Newly drawable elements. An element that just became drawable is not reported in
changedElements. Its snapshot is available from the next paint event. - Per-call cost. Each
drawElementImageToTexturecall allocates and fully rasterizes, about 250 to 550 calls per second in total. This, not compositing, limits the fill rate, which is why nodes are batched into pages. - Cropping. A source rectangle still rasterizes the whole source element at the requested scale before cropping. Zoomed in, a node therefore moves to a page of its own.
- Drawable count. Recording cost scales with the number of drawables (and non-
display:nonecanvas children) on everyrequestPaint. 10,000 always-drawable nodes run at 22 fps even when idle.
- Workers. Composite in a worker with
captureElementImage, and drive culling from the GPU.

