gpucanvas 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Berkant Ay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,90 @@
1
- # Temporary Holding Version
1
+ # gpucanvas
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Put thousands of live DOM nodes on an infinite canvas and let the GPU pan and zoom them.
4
+
5
+ ![The same 5,000 live React screens as plain DOM (left) and in gpucanvas (right), with each side's frame rate measured live](docs/benchmark.gif)
6
+
7
+ 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 with the demo below.
8
+
9
+ Status: early (0.1). The API can still change.
10
+
11
+ ```sh
12
+ npm install gpucanvas
13
+ ```
14
+
15
+ ```tsx
16
+ import { GpuCanvas, CanvasNode } from 'gpucanvas/react';
17
+
18
+ <GpuCanvas style={{ width: '100vw', height: '100vh' }}>
19
+ {cards.map((card) => (
20
+ <CanvasNode key={card.id} x={card.x} y={card.y} width={240} height={150}>
21
+ <Card {...card} />
22
+ </CanvasNode>
23
+ ))}
24
+ </GpuCanvas>;
25
+ ```
26
+
27
+ Nodes stay real DOM: React state, events, CSS and accessibility work as usual. Where WebGPU and
28
+ HTML-in-Canvas are available (Chrome 157+), nodes are snapshotted into a GPU atlas and drawn in
29
+ one instanced draw call. Everywhere else it falls back to a CSS-transformed container with the
30
+ same API.
31
+
32
+ ## Run the demo
33
+
34
+ ```sh
35
+ bun install
36
+ bun run dev # http://localhost:5199/?mode=gpu&n=10000 (mode: auto | gpu | dom)
37
+ ```
38
+
39
+ ## How it works
40
+
41
+ 1. Nodes live inside `<canvas content="drawable">`.
42
+ 2. A node that needs pixels is promoted (`drawable` attribute). In the next paint event its
43
+ snapshot is rasterized with `queue.drawElementImageToTexture` into a texture-array atlas, at a
44
+ power-of-two scale of the zoom.
45
+ 3. After that the node is parked with `display: none`. Every drawable costs Chrome layout and a
46
+ recording on each rendering update, so only nodes waiting for a raster stay drawable.
47
+ 4. A MutationObserver marks a node dirty when its content changes, which re-promotes it.
48
+ 5. Each frame culls nodes against the view and draws every visible one with one instanced quad
49
+ draw. Nodes without a snapshot yet draw as placeholders.
50
+ 6. While the camera moves, only missing snapshots are rasterized. Blurry ones are upgraded once
51
+ it rests, center first. Zooming out keeps the sharper snapshots.
52
+ 7. Only the node under the pointer is live (hit-testable). Pans and zooms cost no DOM work.
53
+
54
+ ## Measured (M-series Mac, Chrome 157, DPR 2, 120 Hz)
55
+
56
+ The 6-second scripted path runs overview, then 100% zoom, then a pan, then overview again.
57
+
58
+ | Nodes | gpu avg fps | gpu p95 | dom avg fps | dom p95 | mount gpu / dom |
59
+ | ------ | ----------- | ------- | ----------- | -------- | --------------- |
60
+ | 1,000 | 120 | 10.1 ms | 120 | 10.1 ms | 1 s / 1 s |
61
+ | 10,000 | 98 | 16.7 ms | 85 | 17.0 ms | 1 s / 1.3 s |
62
+ | 50,000 | 64 | 33.4 ms | 7 | 189.3 ms | 7 s / 13 s |
63
+
64
+ - At 50,000 nodes the overview shows placeholders: nodes under 6 screen pixels wide are not
65
+ rasterized.
66
+ - At 10,000 nodes the overview takes about 6 s to fill.
67
+
68
+ ## Chrome 157 findings (differ from the WICG explainer)
69
+
70
+ - **Hit-test registration.** A drawable is hit-tested only after
71
+ `canvas.updateElementGeometry(el, {})` registers it. The `canvasTransform` option does not
72
+ move the hit area.
73
+ - **Hit-test position.** The hit area is the element's CSS box, so position it with
74
+ `el.style.transform = canvas.getElementTransform(el, drawMatrix)`. The draw matrix maps the
75
+ element's default-size snapshot (CSS px × DPR) to canvas pixels.
76
+ - **Transform changes.** Changing a drawable's CSS transform or pointer-events reports it in
77
+ `changedElements`.
78
+ - **Newly drawable elements.** An element that just became drawable is not reported in
79
+ `changedElements`. Its snapshot is available from the next paint event.
80
+ - **Per-call cost.** Each `drawElementImageToTexture` call allocates and fully rasterizes, about
81
+ 250 to 550 calls per second in total. This, not compositing, limits the fill rate.
82
+ - **Drawable count.** Recording cost scales with the number of drawables (and non-`display:none`
83
+ canvas children) on every `requestPaint`. 10,000 always-drawable nodes run at 22 fps even when
84
+ idle.
85
+
86
+ ## Next
87
+
88
+ - **Keyboard and accessibility.** Parked nodes are `display: none`, so Tab skips them. Needs a
89
+ focus model, such as a mirror or pinning the focused node.
90
+ - **Workers.** Composite in a worker with `captureElementImage`, and drive culling from the GPU.