Splitting text lines and inline shader reveal
I saw Yousuf Soomro's Slot Field and Manoela Ilic's Inline Hover Reveals and wanted to know if one live HTML essay inside an ElementGL canvas can slide neighbouring lines apart vertically on the GPU without reflowing the DOM. Hover, tap or select an anchor word, edit the inline phrase, or switch between pixel blocks and the optical GLSL ribbon.
Starting canvas…
Show the code cached Range line slicing, 3-strip WebGL shader, hit mapping and 2D 9-arg fallback
- One live essay inside the canvas. Semantic paragraphs with inline
<button>and<a>anchors, acontenteditablespan and aPin slottoggle sit inside a singledrawablearticle. - Cached line slicing with
Range.getClientRects(). Reads each anchor's box and full line band relative to#slot-articleat resize or input time, so the animation loop never forces layout. - Three-strip WebGL fragment shader. Shifts
aboveAnchorup andbelowAnchordown bygap / 2, keeps the chosen anchor word steady in place, and fills the cavity with 8 px pixel blocks or an optical GLSL ribbon. - Geometry sync and inverse pointer mapping. Scales
updateElementGeometry()bygeometryUnit()withdataset.hitTick, and maps clicks on slid strips back to rest coordinates. - Nine-argument 2D slice fallback. Cuts the same three horizontal bands with 9-argument
drawElementImage()and restores the article's full hit region with an empty-clip 5-argument draw.
How it works
This page puts Yousuf Soomro's Slot Field (post) together with Manoela Ilic's Inline Hover Reveals (demo) on a single <canvas content="drawable" layoutsubtree>.
Instead of cloning text into separate DOM spans and animating margins or transforms per line, the essay stays one plain <article drawable> inside the canvas.
- Cached line measurement at rest: when the article mounts, resizes or receives
inputinside#editable-line,measureAnchors()creates aRangeover each anchor's containing paragraph and readsgetClientRects(). Merging all inline rects on the same vertical band gives[lineTop, lineBottom]around every ascender and descender without reading layout insiderequestAnimationFrame(). - Single
ElementGLupload insidepaint: the page waits forhasPainted === trueinside the canvaspaintlistener before callingstage.upload(articleEl)(gl.texElementSubImage2D()). Active spring frames reuse that GPU texture and update uniforms only. - Three-strip split with zero DOM reflow: the canvas reserves 32 px of dark backing above and below the article sheet. As
slotGapsprings from0to58 px, the fragment shader slidesaboveAnchorup bygap / 2andbelowAnchordown bygap / 2, fades surrounding words onanchorLineinto ghosted glyphs, and holds the active keyword crisp inside an illuminated capsule. - Two shader cavities: Mode 1 renders quantised 8 px animated pixel blocks and edge scan ticks inspired by Slot Field. Mode 2 renders an iridescent GLSL fluid and optical interference ribbon underneath the live link inspired by Inline Hover Reveals. Under
prefers-reduced-motion: reduce(or the checkbox above),slotGapsnaps in one frame and pixel flicker freezes. - Unshifted anchor hit-testing and shifted strip mapping: because
anchorLinestays atdy = 0 pxwhile outer strips part around it, keepingupdateElementGeometry()at rest aligns the active<button>or<a>1:1 withdocument.elementsFromPoint(). For clicks on slid strips,mapCanvasYToArticleY()inverts±gap / 2back to article layout coordinates so clicking another anchor orPin slotstill lands on the right target. - Nine-argument 2D and plain-HTML fallbacks: switching the Route control to
2D (9-arg slice)swaps in a fresh canvas, retires the WebGL canvas throughwindow.__gfx.retire()and slices the same three strips using 9-argumentdrawElementImage(), ending with an empty-clip 5-argument draw so the hit box isn't shrunk to the last slice. If HTML-in-canvas isn't available or a context is lost, the essay moves into plain HTML without losing your edits.
Live checks
Each check builds an isolated fixture on testStage() and retires its canvas when finished. The visible essay above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
Not verified in Chrome Canary or Chrome 159 for Android yet. Press "Run these 5 checks" above to measure this browser.
- Not verified yet:
ElementGLthree-strip texture upload and shader readback,document.elementsFromPoint()on the anchored<button>while open, spring settle and reduced-motion snap, and 412 px Android touch behaviour.