[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-113141":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":38,"updatedAt":39,"readmeContent":40,"aiSummary":41,"trendingCount":15,"starSnapshotCount":15,"syncStatus":16,"lastSyncTime":42,"discoverSource":43},113141,"gpucanvas","berkantay\u002Fgpucanvas","berkantay","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.","https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F",null,"TypeScript",553,41,1,0,2,43,194,14,82.87,"MIT License",false,"main",true,[26,27,28,29,30,31,32,33,34,35,36,37],"ai-agents","canvas","design-tools","editor","html-in-canvas","infinite-canvas","react","shaders","transitions","typescript","webgpu","wgsl","2026-11-18 13:30:07","2026-11-23 15:53:43","# gpucanvas\n\nPut thousands of live DOM nodes on an infinite canvas: the GPU draws them, an editor selects,\nmoves and resizes them, shaders and transitions run on them, and an AI agent can read them and\npoint at them.\n\n![The same 5,000 live React screens as plain DOM (left) and in gpucanvas (right), with each side's frame rate measured live](docs\u002Fbenchmark.gif)\n\nThe 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](https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F).\n\n- **[Canvas](#how-it-works).** Live React or plain DOM nodes, drawn by WebGPU in one instanced\n  pass. Pan and zoom never touch the DOM, and clicks, typing and state still reach the real\n  elements.\n- **[Editor](#editing).** Click to select, double-click to go a layer deeper, down to any element\n  or React component. Move and resize with snapping guides.\n- **[Shader effects](#shader-effects).** Run WGSL on live components: a glass lens, frost,\n  shockwaves, glitch, VHS, or your own.\n- **[Snapshots](#snapshots).** Any node as an image, pixel diffs between versions, and a\n  filmstrip of its history.\n- **[Agent view](#agent-view).** What is on the canvas as a short JSON tree with ids, and an\n  image of any region, for an AI agent to read and point at.\n- **[Transitions](#transitions).** Dissolve, wipe or fade a node out and another in, on the\n  GPU, while both stay live.\n- **[Marks](#marks).** Arrows between elements, comment pins, notes and live cursors that\n  follow the camera.\n\n![An agent cursor flags a heading, links two buttons and drops a pin; the screen wipes out and dissolves back; a glass lens follows the pointer; shockwaves ripple from clicks](docs\u002Ffeatures.gif)\n\nMarks from an agent, a wipe and a dissolve, the glass lens and shockwaves, all on live\ncomponents. Recorded in Chrome from the demo.\n\nHow it works, with the benchmarks and what Chrome's HTML-in-Canvas does differently from the\nexplainer: [gpucanvas: 5,000 Live React Screens on a WebGPU Infinite Canvas](https:\u002F\u002Fberkant.me\u002Fblog\u002Fgpucanvas-webgpu-infinite-canvas).\n\n## Try it\n\nOpen **[berkantay.github.io\u002Fgpucanvas](https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F)** in Chrome 157 or\nlater. Thirty agent cursors build the first view, then the camera pulls out to all 5,000 screens.\n\n- Click a screen to select it, double-click to go deeper, drag to move it. Double-click a text\n  field to type in it, or switch the toolbar to Interact and use the screens like a normal page.\n- In Interact, every button does something. Continue, Sign in and Back move the camera to the\n  next screen like a clickable prototype, Notifications and More open panels, Export saves a\n  CSV, Send adds the message and Share copies the link.\n- The toolbar holds every setting: renderer, number of screens, Edit or Interact, what a click\n  selects, the shader effect, the agent cursors and the theme. They apply live, and the URL\n  remembers them.\n- Pick a shader effect in the toolbar, or open one directly:\n  [glass](https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F?effect=glass),\n  [shockwave](https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F?effect=shockwave) (click anywhere),\n  [frost](https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F?effect=frost),\n  [glitch](https:\u002F\u002Fberkantay.github.io\u002Fgpucanvas\u002F?effect=glitch).\n- Select a screen and press `D` to dissolve it, `W` to wipe it, or `S` to save it as a PNG.\n- In the console, `agentView.describe()` lists what is in view, and `marks` draws on it.\n- Press `b` to run the benchmark tour, `f` to fit every screen in view, `t` to switch the theme.\n- On a phone: pinch to zoom, drag to pan, tap to use a screen.\n\nThe GPU path needs WebGPU and HTML-in-Canvas. Chrome 157 and later on a computer has both on by\ndefault, so the demo opens on the GPU path. On older Chrome or other Chromium builds, turn it on\nwith `chrome:\u002F\u002Fflags\u002F#canvas-draw-element` and relaunch.\n\nWithout HTML-in-Canvas the demo runs the DOM fallback with 1,000 screens and says so. Phones start\nsmaller so the tab is not killed for memory: 1,000 screens on the GPU path and 250 as DOM. Firefox,\nSafari and every iPhone or iPad browser have no HTML-in-Canvas yet, so they run the DOM version and\nsay so.\n\nStatus: early (0.4). The API can still change.\n\n```sh\nnpm install gpucanvas\n```\n\n```tsx\nimport { GpuCanvas, CanvasNode } from 'gpucanvas\u002Freact';\n\n\u003CGpuCanvas style={{ width: '100vw', height: '100vh' }}>\n  {cards.map((card) => (\n    \u003CCanvasNode key={card.id} x={card.x} y={card.y} width={240} height={150}>\n      \u003CCard {...card} \u002F>\n    \u003C\u002FCanvasNode>\n  ))}\n\u003C\u002FGpuCanvas>;\n```\n\nNodes stay real DOM: React state, events, CSS and accessibility work as usual. Where WebGPU and\nHTML-in-Canvas are available (Chrome 157+), nodes are snapshotted into a GPU atlas and drawn in\none instanced draw call. Everywhere else it falls back to a CSS-transformed container with the\nsame API.\n\n## Editing\n\n`bindEditor` turns the canvas into an editor: select, drill in, move and resize. The GPU draws\nthe outlines, 2 CSS pixels wide at any zoom, and they follow their element's layout. Names,\nsizes, handles and snapping guides sit in a thin overlay above it.\n\n```ts\nimport { bindEditor } from 'gpucanvas';\n\nconst editor = bindEditor(canvas, {\n  pick: 'element', \u002F\u002F 'node' (default), 'element', or a function\n  trigger: 'click', \u002F\u002F an edit mode; the default 'shift-click' leaves clicks to your components\n  onChange: (layers) => console.log(layers),\n  onTransform: ({ phase, layers, to }) => {\n    \u002F\u002F The editor never moves anything itself. Apply `to` with updateNode, state or styles.\n  },\n});\n```\n\nA click selects the outermost layer under the pointer, a whole node. Each double-click goes one\nlayer deeper, and later clicks stay at that depth. Wrappers the size of their parent are skipped,\nso every double-click visibly changes something.\n\n| Input              | Does                                                                         |\n| ------------------ | ---------------------------------------------------------------------------- |\n| Double-click       | One layer deeper; on a text field, starts typing in it                       |\n| Enter, Shift+Enter | First child, parent                                                          |\n| Tab, Shift+Tab     | Next and previous sibling                                                    |\n| Escape             | Ends typing, cancels a drag, then goes up a layer, then clears               |\n| Drag               | Moves, snapping to the edges and centers of neighbors (Shift locks the axis) |\n| Handles            | Resize (Shift on a corner keeps the ratio)                                   |\n| Drag on open space | A box that selects the layers it touches, inside the layer you are in        |\n\nWith the default `trigger: 'shift-click'`, the same works with Shift held, and clicks still reach\nyour components. A layer is an array of elements, so one layer can be a component that renders\nseveral. `pick` decides the layers:\n\n- `'node'`: whole nodes only.\n- `'element'`: every element from the node down to the one under the pointer.\n- a function of that element, returning the layers that hold it, outermost first.\n\nIn React, `useEditor` gives the selection as state, and `pickComponents` makes the layers React\ncomponents:\n\n```tsx\nimport { labelComponent, pickComponents, useEditor } from 'gpucanvas\u002Freact';\n\n\u002F\u002F Inside \u003CGpuCanvas>:\nconst { selected, clear } = useEditor({ pick: pickComponents, label: labelComponent });\n\u002F\u002F Click a screen, double-click: SignIn, SignInCard, Button.\n```\n\n`pickComponents` and `componentOf` read React's internal fibers, as click-to-component tools do.\nProduction builds usually minify component names, so mark components with your own attributes\nwhen you need names there.\n\nThe building blocks, for your own interactions:\n\n```ts\ncanvas.getElementAt(point); \u002F\u002F deepest element at a world point\ncanvas.getElementRect(el); \u002F\u002F any element's rect in world units\ncanvas.getNodeOf(el); \u002F\u002F the node that holds it\ncanvas.getNodesIn(rect); \u002F\u002F nodes overlapping a world rect\ncanvas.setSelection(elements); \u002F\u002F outline these; [] clears\ncanvas.setHover(el); \u002F\u002F a lighter outline; null clears\ncanvas.screenToWorld(point); \u002F\u002F surface pixels to world units, and worldToScreen back\n```\n\nColors are the `selectionColor` and `hoverColor` options. In the demo, the toolbar switches between\nEdit and Interact (clicks reach the components) and picks components, elements or whole screens.\n\n## Shader effects\n\nComponents stay live DOM, and the GPU draws them through a shader. One call per node:\n\n```ts\nimport { effects } from 'gpucanvas';\n\ncanvas.setEffect(node, effects.ripple); \u002F\u002F the effect's default parameters\ncanvas.setEffect(node, effects.glow, [1, 0.4, 0.2, 32]); \u002F\u002F orange, 32 px reach\ncanvas.setEffect(node, null); \u002F\u002F back to plain\n```\n\nBuilt in:\n\n- Following the pointer: `glass` (a magnifying lens), `frost` (ice, clear around the pointer),\n  `dither` (a lens of big dithered pixels).\n- On each press: `shockwave`, a ring that bends the node as it spreads.\n- Running on their own: `glitch`, `vhs`, `glow`, `hue`, `ripple`.\n- Still: `blur`, `pixelate`, `grayscale`.\n- [Transitions](#transitions): `dissolve`, `wipe` and `fade`, for a node leaving or arriving\n  (the first parameter is the progress, 0 to 1).\n\nAnimated effects draw every frame while their node is in view; still ones cost nothing once\ndrawn.\n\nYour own is a WGSL function over the node's pixels:\n\n```ts\nimport { defineEffect } from 'gpucanvas';\n\nconst scanlines = defineEffect({\n  name: 'scanlines',\n  animated: true,\n  params: [3], \u002F\u002F line spacing in CSS pixels\n  wgsl: \u002F* wgsl *\u002F `\n    fn effect(input: EffectInput) -> vec4f {\n      let color = source(input.uv);\n      let y = input.uv.y * input.size.y + input.time * 20.0;\n      return color * (0.85 + 0.15 * step(0.5, fract(y \u002F input.params.x)));\n    }`,\n});\n```\n\n`EffectInput` has `uv` (0 to 1 across the node), `size` in CSS pixels, `time` in seconds,\n`zoom`, the four `params`, the `pointer` and the last `press` in the node's uv, and\n`sincePress` in seconds. `source(uv)` reads the node's pixels, premultiplied, and is\ntransparent outside it; `hash` and `noise` give random values. An effect that draws past its\nnode, like a glow, declares how far with `pad`. Effects read the node's whole snapshot, so very\nclose in they are softer than plain nodes. In React, `\u003CCanvasNode effect={effects.glass}>` does\nthe same.\n\nThe DOM backend shows effects that have a `css` look as a CSS `filter` (animated ones as filter\nanimations) and the rest as plain nodes. The demo's toolbar puts one effect on every component.\n\n## Snapshots\n\nEvery node is already drawn by the GPU, so its pixels are one call away, with no headless\nbrowser:\n\n```ts\nimport { diffImages, recordFilmstrip, toBlob } from 'gpucanvas';\n\nconst before = await canvas.snapshot(node, { scale: 2 }); \u002F\u002F ImageData, drawn fresh\nconst png = await toBlob(before); \u002F\u002F a PNG Blob\n\n\u002F\u002F ...the screen changes...\nconst after = await canvas.snapshot(node, { scale: 2 });\nconst { changed, bounds, image } = diffImages(before, after); \u002F\u002F what moved, and where\n\n\u002F\u002F A snapshot after every change, once it settles.\nconst strip = recordFilmstrip(canvas, node, { scale: 0.25, max: 30 });\nstrip.frames; \u002F\u002F [{ at, image }, ...]\nstrip.stop();\n```\n\nA snapshot is the node as it looks now, at any scale, whether or not it is in view. It takes a\npaint or two, about 40 ms for a 1,500 by 1,000 pixel screen. In the demo, select a screen and\npress `S` to save it. Snapshots need the GPU backend; the DOM backend rejects.\n\n## Agent view\n\nAn agent reads the canvas the way a person sees it: what is there, what it says, and where:\n\n```ts\nimport { createAgentView } from 'gpucanvas';\n\nconst view = createAgentView(canvas);\nview.describe(); \u002F\u002F what is in view, as JSON\n\u002F\u002F [{ id: 'e35', tag: 'div', rect: { x: -3552, y: -2561, width: 1496, height: 958 }, children: [\n\u002F\u002F   { id: 'e6', tag: 'h1', role: 'heading', text: 'Welcome back', rect: { ... } },\n\u002F\u002F   { id: 'e18', tag: 'input', role: 'textbox', name: 'Email', rect: { ... } },\n\u002F\u002F   { id: 'e23', tag: 'input', role: 'checkbox', name: 'Keep me signed in', checked: true, ... },\n\u002F\u002F   { id: 'e25', tag: 'button', role: 'button', text: 'Sign in', rect: { ... } }, ...] }]\n\nview.element('e25'); \u002F\u002F the element behind an id\nawait view.capture('e6', { scale: 2 }); \u002F\u002F ImageData of that element\nawait view.capture({ x: 0, y: 0, width: 4000, height: 3000 }, { scale: 0.25 }); \u002F\u002F any region\n```\n\nWrappers that add nothing are left out, so a sign-in screen is about 35 entries and 3.5 KB of\nJSON, read in 3 ms. Pass `rect` to read another region and `name` to label elements with your\nown names, such as their React component's. `capture` needs the GPU backend.\n\n## Transitions\n\nAny effect whose first parameter is progress (0 whole, 1 gone) animates as a transition:\n`dissolve`, `wipe` and `fade` are built in.\n\n```ts\nimport { animateEffect, effects, swapNodes } from 'gpucanvas';\n\nawait animateEffect(canvas, node, effects.wipe, { duration: 600, params: [90] }); \u002F\u002F wipe downward\nawait animateEffect(canvas, node, effects.wipe, { from: 1, to: 0 }); \u002F\u002F and back\n\n\u002F\u002F One screen burns away while the next appears in its place.\nawait swapNodes(canvas, oldScreen, newScreen, { effect: effects.dissolve, duration: 800 });\ncanvas.removeNode(oldScreen);\n```\n\nA node that ends whole loses the effect; one that ends gone stays hidden until it is removed.\nStarting another animation on a node replaces the running one, which resolves `false`. In the\ndemo, select a screen and press `D` to dissolve it or `W` to wipe it. The DOM backend fades.\n\n## Marks\n\nDraw on top of the nodes. Marks follow the camera and the elements they are attached to, and\nstay the same size on screen at any zoom:\n\n```ts\nimport { createMarks } from 'gpucanvas';\n\nconst marks = createMarks(canvas);\nmarks.connect(button, nextScreen, { label: 'goes to' }); \u002F\u002F a curved arrow\nmarks.pin(card, { label: '3', text: 'Rename to Continue?', onClick: openThread });\nmarks.note(view.element('e6'), 'This heading is 2px off the grid'); \u002F\u002F what an agent means\nconst cursor = marks.cursor('Ada', { color: '#e11d48' });\ncursor.move({ x: 120, y: 80 }); \u002F\u002F glides there, in world units\nmarks.clear();\n```\n\nArrows and pins also take a world point in place of an element. Marks are SVG and HTML in a\nlayer above the canvas, so they work with both backends. In the demo, both are on `window`:\n`agentView` and `marks`.\n\n## Run the demo\n\n```sh\nbun install\nbun run dev        # http:\u002F\u002Flocalhost:5199\u002F?mode=gpu&n=10000  (mode: auto | gpu | dom)\n```\n\n## Releases\n\nPublishing a GitHub release for a `vX.Y.Z` tag that matches `package.json` publishes the package\nto npm from GitHub Actions, with provenance, through npm trusted publishing. See\n[release.yml](.github\u002Fworkflows\u002Frelease.yml).\n\n## How it works\n\n1. **Pages.** Nodes are live DOM inside `\u003Ccanvas content=\"drawable\">`, packed side by side into\n   pages of 2048 CSS pixels. Chrome records a page as one snapshot, so one\n   `drawElementImageToTexture` call rasterizes dozens of nodes at once.\n2. **Rasterize, then park.** A page with nodes waiting for pixels becomes `drawable`. In the next\n   paint event it is drawn into a texture-array atlas, whole or one node at a time when only a\n   few changed. Then it is parked with `content-visibility: hidden`, which keeps layout but skips\n   paint, so the browser spends nothing on it per frame.\n3. **Thumbnails first.** Every node gets a 1\u002F16 scale thumbnail in an atlas layer that is never\n   evicted, so a zoomed-out view of thousands of screens is always filled in. Sharper snapshots\n   go on top at power-of-two scales, so zooming reuses them.\n4. **Tiles up close.** Past 100% zoom on a 2x display, only the visible part of a node is\n   rasterized, as sharp tiles, center first. While its content animates, one half-resolution preview stands in.\n5. **One draw call.** Each frame culls nodes against the view and draws every visible one with\n   one instanced quad draw, or one per run of nodes sharing a shader effect. Panning and zooming\n   never touch the DOM. Raster work has a\n   per-frame budget, so the camera stays smooth while pixels fill in.\n6. **Live updates.** A MutationObserver marks a node dirty when its content changes, and\n   loading images, web fonts and CSS transitions trigger a redraw. Animated content on nodes\n   under 200 screen pixels refreshes at most four times a second.\n7. **Input.** Only the page under the pointer is registered for hit testing, and its canvas\n   transform puts the node under the pointer exactly where the GPU drew it. Clicks, typing, selection and\n   hover all go to the real element. A focused node keeps its page live. Touch has no hover, so a\n   tap makes the node under the finger live and hands the click to the element it landed on. A\n   two-finger pinch zooms and pans the camera wherever the fingers land.\n\n## Measured (M-series Mac, Chrome 157, 1600 x 900 window, DPR 1)\n\nThe demo's benchmark (press `b`) runs a 30-second tour: a message typed and sent, a chart\nanimating, a push to 500% zoom, shift-click picks and a selection sweep, while 30 agent cursors\nbuild screens around the view. Every frame is timed. At 5,000 screens it measures 113 to 115 fps\nfor gpucanvas and 18 to 20 for DOM, and 138 for gpucanvas in the effects run below.\n\nThe table below was measured with the 0.1 benchmark, a 94-second session from the overview into\nclusters of app screens, close-ups up to 500% zoom, 20 clicks and typed messages, then back out.\n\n| Screens | gpucanvas avg fps | gpucanvas p95 | DOM avg fps | DOM p95  | Mount gpucanvas \u002F DOM |\n| ------- | ----------------- | ------------- | ----------- | -------- | --------------------- |\n| 5,000   | 117               | 9.2 ms        | 23          | 50.2 ms  | 1.2 s \u002F 1.3 s         |\n| 10,000  | 108               | 16.7 ms       | 9           | 133.8 ms | 1.8 s \u002F 3.4 s         |\n\nDOM is the same screens in one CSS-transformed container, which is also the fallback backend.\n\nShader effects on every one of the 5,000 screens, the same 30-second tour, vsync off:\n\n| Effect         | gpucanvas avg fps | p95     |\n| -------------- | ----------------- | ------- |\n| none           | 138               | 15.2 ms |\n| glow           | 135               | 15.6 ms |\n| blur (32 taps) | 138               | 16.7 ms |\n| glass          | 122               | 18.2 ms |\n| frost          | 146               | 13.8 ms |\n\nEffects draw from each node's snapshot in the same pass, so most cost nothing measurable; glass,\nwhich samples around the pointer with a rim and shadow, costs about 12%. Each figure is one run,\nso a gap of a few percent, like frost above none, is noise rather than a speedup.\n\n## Chrome 157 findings (differ from the WICG explainer)\n\n- **Hit-test registration.** A drawable is hit-tested only after\n  `canvas.updateElementGeometry(el, options)` registers it.\n- **Hit-test position.** Chrome 157 hit tests at `options.canvasTransform`, a matrix in CSS\n  pixels from the element's border box to the canvas, and `getElementTransform(el)` returns it.\n  Chrome 156 ignored `canvasTransform` and hit tested at the CSS box, positioned with\n  `el.style.transform = canvas.getElementTransform(el, drawMatrix)`. gpucanvas handles both.\n- **Transform changes.** Changing a drawable's CSS transform or pointer-events reports it in\n  `changedElements`.\n- **Newly drawable elements.** An element that just became drawable is not reported in\n  `changedElements`. Its snapshot is available from the next paint event.\n- **Per-call cost.** Each `drawElementImageToTexture` call allocates and fully rasterizes, about\n  250 to 550 calls per second in total. This, not compositing, limits the fill rate, which is\n  why nodes are batched into pages.\n- **Cropping.** A source rectangle still rasterizes the whole source element at the requested\n  scale before cropping. Zoomed in, a node therefore moves to a page of its own.\n- **Drawable count.** Recording cost scales with the number of drawables (and non-`display:none`\n  canvas children) on every `requestPaint`. 10,000 always-drawable nodes run at 22 fps even when\n  idle.\n\n## Next\n\n- **Keyboard and accessibility.** Parked pages use `content-visibility: hidden`, so Tab skips\n  their nodes. A focused node already stays live; moving focus across pages needs a focus model.\n- **Workers.** Composite in a worker with `captureElementImage`, and drive culling from the GPU.\n","gpucanvas 是一个基于 WebGPU 的无限画布渲染框架，支持在单次 GPU 实例化绘制中高效呈现数千个可交互的实时 DOM 或 React 节点。其核心能力包括：纯 GPU 驱动的平移\u002F缩放（不触碰 DOM）、所见即所得的编辑器（选择、拖拽、缩放、逐层深入）、WGSL 着色器特效（玻璃、冲击波等）、节点级快照与像素差异比对、AI 可读的结构化节点树及区域截图、GPU 加速过渡动画（溶解\u002F擦除），以及标注标记（箭头、便签、跟随光标）。适用于高密度 UI 原型设计、可视化调试、AI 代理界面交互训练、大规模组件沙盒及设计系统演示等场景。","2026-11-24 04:44:56","CREATED_QUERY"]