Momotarō, chapter two
The peach boy sets out
Grown strong, Momotarō packed three kibi dango and set out for Onigashima.
I wanted to know if a paper pop-up book can be made of live HTML: a story spread whose cutouts stand up on synchronised hinges as the book opens, while the buttons and the <details> printed on each cutout stay clickable at every fold angle. Drag the open angle, share a dango, or tap an animal.
Momotarō, chapter two
Grown strong, Momotarō packed three kibi dango and set out for Onigashima.
Share dango to gather the party, then set sail.
Ogre island, across the sea.
Gate: closedHTMLSurfaces moves the story page, the riverbank page and the three cutouts into the canvas as drawable children and uploads each with texElementSubImage2D().clip-path and border-radius; transparent pixels are dropped with alphaTest on the plane.surfaces.update() calls updateElementGeometry() each frame so the browser's hit test follows the raised plane.elementFromPoint() along the projected centre line of a button and compares where hits start and stop with the drawn edges.
This experiment takes inspiration from Thomas Nattestad's Momotarō Pop-Up Book in html-in-canvas-fun.
The spread is five ordinary elements: an <article> story page, a riverbank page, and three cutouts carrying live <button> and <details> elements.
Without HTML-in-canvas or WebGL they stay in the page as a plain column.
With both, Three.js draws each element on a plane through HTMLSurfaces from /lib/html3d.js.
The story page turns about the spine at the open angle.
Each cutout is hinged on the floor page at its own distance from the spine, and its top edge is held a few degrees under the turning page, the way a paper strip pulls a real pop-up up.
That gives every cutout its own raise angle from one slider: the companions stand first, Momotarō next, and the island last, all upright by about 70 degrees.
Every frame surfaces.update() sends each plane's projective matrix to updateElementGeometry(), so the browser hit tests the button on a tilted cutout where it is drawn.
A cutout that faces away from the camera, which is every cutout when the book is closed, is parked off the canvas so it cannot be clicked through the page.
Clicking a button changes its element, the paint event reports it, and only that cutout's texture is uploaded again.
The animation loop runs only while the open angle is moving, and each move is timed by the clock rather than by frames, so a slow phone finishes the opening fold in 1.1 seconds like a fast one. Once the book settles nothing is drawn until something changes.
These checks wait for a tap because they read pixels from the WebGL canvas. They drive the visible book: they scroll it into view, move the open angle, press buttons and open the disclosure, then put everything back.
161.0.8200.0 on 2026-12-04 at 412x915 (DPR 2.625, SwiftShader WebGL): all 7 live checks passed with zero JS errors, zero lost contexts, zero open snapshots and zero horizontal overflow on a 756x820 canvas (0.62 MP, 9.5 MB). The drawing buffer is the CSS size times a pixel ratio capped at 2.40.3, 58.3 and 90 degrees, and at 72 degrees all three stood at 90. A sweep from 0 to 180 degrees kept every top edge under the turning page and no hinge ever fell back.elementFromPoint() along the drawn centre line of each control found its hit edges within 0.8px of its drawn edges, and its getBoundingClientRect() centre within 0.3px of its drawn centre, at 40 and at 72 degrees. That covers the Share button (top -0.4px, bottom 0.1px at 40 degrees, with its cutout tilted at 78 degrees), the bottom-most control (the monkey button, -0.7px and -0.4px), Next line on the turning story page (-0.4px and 0.1px at 72 degrees, -0.7px and 0.0px at 40 degrees, when it is drawn only 5.1px tall) and the island's <summary> (-0.8px and -0.3px).3 to 2), moved the story to its next line and opened the <details>, and each click uploaded that surface's texture again. With the book closed, the Share button was not found where it would be drawn, because HTMLSurfaces parks a cutout that faces away.getBoundingClientRect() over a screenshot taken during a frame-counted opening fold that was still at 69 degrees on SwiftShader, and Next line looked 10 to 12 px low. Settled, the same overlay lines up. A clock-timed fold and a loop that stops when the book settles fixed it.offsetTop is rounded and measured from the parent's padding edge, which put my first projection of the <summary> 1.4 px off. The check now measures an untransformed copy of the surface. With line-height: 1.2 the summary text also reached 1 px above its box, where elementFromPoint() still found it.