A lens over live DOM

Drag across the card. Each lens draws the patch of page under it once, at the lens's own magnification, and a shader bends it, so 4px text comes out sharp. What's under the lens is still the page, and you can click and type through it.

Specimen sheet

Regular text, then the small print. Everything here is ordinary markup inside a <dom-lens> element.

The quick brown fox jumps over the lazy dog. Sphinx of black quartz, judge my vow. Pack my box with five dozen liquor jugs. How vexingly quick daft zebras jump. The five boxing wizards jump quickly. Jackdaws love my big sphinx of quartz. Terms apply. Past performance isn't a guide to future results. Contains small parts. Objects in the lens are closer than they appear. Don't operate heavy machinery while reading 7px type. Void where prohibited. Batteries not included. Some assembly required.

This line is set at four pixels. If you can read it without the lens, the lens is on. HTML-in-canvas replays paint records, so scale is free.

100: 30180: 15260: 8
idwhms
a91f12807203.21
c07e6403600.98
e3b2192010807.44
04d83201800.31

Click the button through the lens, type in the field, or press Tab and the lens follows focus. On a touch screen the lens rides above your finger and the page doesn't scroll from the card (switch the lens off, or pin it, to scroll from the card).

<script type="module" src="/lib/dom-lens.js"></script>

<dom-lens mode="glass" zoom="2.4" radius="120">
  <section>…your markup, unchanged…</section>
</dom-lens>

Measure it on this device

The fisheye used to be a mesh of clipped triangles: the element's paint record was replayed once per triangle, up to 199 times a frame. I rebuilt it so that every lens is two replays and one shader pass, on WebGPU where it works and WebGL where it does not. This sweeps the lens across the card each way and times the frames on this device. “Patch px” is the side of the square drawn for the lens: if frames come slowly while the lens moves it is drawn smaller, then sharpened when the lens rests.

Show the code a lens over real markup
  1. Wrap any markup in <dom-lens>. The markup isn't changed.
  2. Load the element and set attributes. mode, zoom, radius, off, and x, y with pinned to hold the lens still. $ is getElementById.
  3. Inside: the markup is slotted into a drawable canvas by this shadow root.
  4. Inside: draw the patch of page under the lens, magnified, then run it through a shader. drawElementImage() under a scale makes the browser draw the text again at that size, so it's sharp. That square goes to WebGPU as a texture, or to WebGL where WebGPU is missing, the lens shader bends it, and the result is drawn back over the page.
  5. Inside: the patch becomes a texture. It is copied straight out of the 2D canvas. This is the WebGL route; the WebGPU one is upload() in /lib/lens-gpu.js.
  6. A lens is one GLSL function. This is the plain magnifier; the glass, fisheye and other lenses are in the same file.
  7. The whole element. The shaders are in /lib/lens-gl.js (GLSL) and /lib/lens-gpu.js (WGSL).

How it works

Live checks

ResultExperimentDetail