The text you see isn't text
Click into the box below and type. Every glyph is a WebGL texture rendered from the last SnapDOM capture. The editable DOM is invisible, and updates cross-fade in.
A transparent contenteditable proxy gives the browser a real caret and keystrokes; a hidden source element mirrors the text and is what SnapDOM captures. A defineExports plugin feeds each capture into a WebGL renderer that double-buffers two textures and cross-fades between them.
What you're looking at
You get a blinking caret and text selection. The glyphs are pixels in a WebGL texture captured from a hidden DOM element and mixed into the canvas under your cursor. The shader dropdown changes only what the fragment shader does with the finished frame.
Try it
Type, paste or press Enter. The browser handles the caret and selection; WebGL paints the captured letters.
Type here
This text is real DOM, but you're seeing it as a WebGL texture kept in sync by SnapDOM.
How it works
A transparent proxy owns the caret
The
.input-layersits on top of the WebGL canvas with transparent text and background. It gives the browser somewhere to place a caret and receives keyboard and paste events; the caret and selection stay visible.Every edit is mirrored to a hidden element
On every
inputevent, paste, and Enter (abeforeinputoverride inserts a literal newline instead of lettingcontenteditablecreate a new<div>), the proxy's text is copied into the hidden#dom-sourceelement andrefresh()runs.refresh()coalesces burstsSame
dirty/workingloop as the live-mirror demo: input during a capture is flagged dirty and picked up by the running loop. It captures#dom-sourcewith theseamlessWebglplugin.The plugin exports into the renderer
The plugin's
defineExportsreturns awebglexport that hands the capture's URL torenderer.update(ctx.export.url)instead of returning an image.The idle texture is loaded, not the visible one
SeamlessRenderer.update()loads the new capture into whichever of its two textures (currentornext) is off screen, then starts a roughly 110ms blend toward it.The shader mixes, then the effect applies
The fragment shader mixes
beforeImageandafterImageby ablenduniform that ramps 0 1 over that window; the selected shader runs on the result.
Why this needed a plugin
SnapDOM's core exports return a finished image. defineExports lets a plugin register a named export (here webgl) that does something else with the render, such as pushing it into one of two alternating GPU textures.
The difference from the live-mirror demo is architectural. Splitting the caret owner from the capture source makes the transition seamless: the canvas never waits on a capture, it is always mid-blend between two textures it already has while the hidden source is captured again.
Copy-paste example
The plugin factory forwards a capture's URL to the renderer you hand it:
function seamlessWebgl (renderer) {
let started = 0
let elapsed = 0
return {
name: 'seamless-webgl',
beforeSnap () { started = performance.now() },
afterRender () { elapsed = performance.now() - started },
defineExports () {
return {
webgl: async ctx => {
const canvas = await renderer.update(ctx.export.url)
perfLabel.textContent = `${elapsed.toFixed(0)} ms · texture swapped`
return canvas
}
}
}
}
}
The usage calls the export through the generic capture.to('webgl') rather than capture.toWebgl(). Both work; .to(name) invokes a plugin-defined export without SnapDOM knowing its name ahead of time:
const plugin = seamlessWebgl(renderer)
let dirty = false
let working = false
async function refresh () {
dirty = true
if (working) return
working = true
while (dirty) {
dirty = false
const capture = await snapdom(source, { plugins: [plugin] })
await capture.to('webgl')
}
working = false
}
Limits and things to watch
The transparent-proxy trick works for plain text only; rich text and IME composition edge cases need more care. This proxy reduces Enter to a literal newline and paste to plain text. Double-buffering costs one extra WebGL texture of GPU memory over the live-mirror demo, worth it only when the crossfade is the point.
Hook contracts and custom exports: plugin API and PLUGIN_SPEC.md.