<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>HTML-in-canvas experiments</title>
<link>https://html-in-canvas.page/</link>
<atom:link href="https://html-in-canvas.page/feed.xml" rel="self" type="application/rss+xml"/>
<description>Each new experiment with the HTML-in-canvas API on html-in-canvas.page: the question it asks, how it works and what I found.</description>
<language>en-gb</language>
<lastBuildDate>Mon, 23 Nov 2026 00:00:00 +0000</lastBuildDate>
<image><url>https://html-in-canvas.page/social.jpg</url><title>HTML-in-canvas experiments</title><link>https://html-in-canvas.page/</link></image>
<item>
<title>Demos and interface work by other people</title>
<link>https://html-in-canvas.page/elsewhere/</link>
<guid isPermaLink="true">https://html-in-canvas.page/elsewhere/</guid>
<pubDate>Mon, 23 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>links</category>
<category>html-in-canvas</category>
<category>Open UI</category>
<category>inspiration</category>
<description>Other people's HTML-in-canvas demos and libraries, interface work I'd like to rebuild with native elements drawn by a canvas, and the proposed controls I'm watching. Every entry is credited and links to the original. A weekly search adds to it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/elsewhere/"><img src="https://html-in-canvas.page/elsewhere/social.jpg" width="1200" height="630" alt="The page &quot;Demos and interface work by other people&quot;"></a></p>
<p>
I keep finding things other people have made that I want to point at: demos built with HTML-in-canvas, and interface
work that isn't built with it and looks like it could be. This is the list. Every entry names who made it and links to
where they published it.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/elsewhere.md">findings/elsewhere.md</a> in the repository.</p>
<p>Measured on 2026-11-23 from the cloud container, with curl and with the test browser (C157). The page is a list of links and draws nothing in a canvas, so it has no live checks.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Do the outside links on the page load?</td><td>measured: 102 of 122 answered 200</td><td>91 answered a plain request. 11 more (<code>*.vercel.app</code>, <code>tympanus.net</code>, <code>ui-feed.dev</code>, <code>html-in-canvas.vittoretrivi.dev</code>) answered 403 to a plain request and 200 in the test browser.</td></tr>
<tr><td>The other 20</td><td>not verified</td><td>All are <code>github.com</code> pages, which the cloud container refuses.</td></tr>
<tr><td>The 33 links to posts on X</td><td>not verified</td><td>X answers 200 to any request, so the count above says nothing about them. They come from the work pages on Memorables.</td></tr>
<tr><td>Does the page hold still while it loads?</td><td>measured: yes</td><td><code>npm run check:jank -- /elsewhere/</code>: layout shift 0, no canvas. The list is static HTML written by <code>node tools/elsewhere/build.mjs</code>.</td></tr>
<tr><td>Does it fit a phone?</td><td>measured: yes</td><td>412 px wide: <code>scrollWidth</code> 412, 75 cards in one column.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A description field that holds <code>&lt;input type="range"&gt;</code> as text is read as a tag by anything that treats the field as HTML (the feed does). The fields <code>title</code>, <code>what</code> and <code>note</code> are HTML: element names are written <code>&amp;lt;input&amp;gt;</code>, and <code>&lt;code&gt;</code> is the only tag the build accepts.</li>
<li><code>/elsewhere/feed.xml</code> is written by <code>tools/feed/site-build.mjs</code> (pull request 133) from the same <code>entries.json</code>. The guid of a feed item is the page address plus <code>#id</code>, so an entry's <code>id</code> must not change once it is published.</li></ul>
<h3>Not verified</h3>
<ul><li>The "how it could be drawn" line on each entry under "Interface work I'd like to rebuild". Each is a plan made from a description. A page that builds one records its own results.</li>
<li>That each X post still exists and shows what Memorables describes.</li></ul>
<p><a href="https://html-in-canvas.page/elsewhere/">Open Demos and interface work by other people</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Controls that join and split like drops</title>
<link>https://html-in-canvas.page/liquid-shapes/</link>
<guid isPermaLink="true">https://html-in-canvas.page/liquid-shapes/</guid>
<pubDate>Mon, 23 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>ctx.filter</category>
<category>source-atop</category>
<category>details</category>
<description>A &lt;button&gt; whose arrow pinches off, a &lt;nav&gt; dock that bulges round a link, and a &lt;details&gt; menu that pours out of its summary. The canvas blurs a copy of itself, cuts it at a threshold and draws the elements again inside the outline, so the labels stay sharp.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/liquid-shapes/"><img src="https://html-in-canvas.page/liquid-shapes/social.jpg" width="1200" height="630" alt="The page &quot;Controls that join and split like drops&quot;"></a></p>
<p><strong>Question:</strong> The CSS way to make shapes join like drops is a blur and a hard contrast on a wrapper, which ruins any text inside. Can a canvas do the same to native controls and keep their labels, focus rings and hit boxes?</p>
<p><strong>Short answer:</strong> Yes, in 2D. A blurred <code>drawImage()</code> copy of the canvas, drawn back through an SVG threshold filter, gives the joined outline, and <code>source-atop</code> keeps the second draw of each element inside it.</p>
<p>
Three native controls whose shapes behave like liquid. Hover or tap the button and its arrow pinches off. Move over the dock and it bulges round the nearest link. Tap a link and it leaves the bar as a drop, then falls back in as the current one. Open the menu and its items pour out of the button.
Each one is a <code>&lt;button&gt;</code>, a <code>&lt;nav&gt;</code> of links or a <code>&lt;details&gt;</code>, drawn by a canvas, and the keyboard works on all of them.
</p>
<h3>How it works</h3>
<p>I found seven demos in one month that join and split shapes this way (they're on <a href="https://html-in-canvas.page/elsewhere/#ui">the list of other people's work</a>). The usual way to do it on the web is a filter on a wrapper: a blur, then a contrast high enough to turn the soft edge back into a hard one. Two blurred shapes that are close overlap, so the hard edge runs round both. Lucas Bebber wrote it up on <a href="https://tympanus.net/codrops/2015/03/10/creative-gooey-effects/">Codrops in 2015</a>. The filter treats a label like any other shape, so the text has to live in a second layer on top that is moved in step by hand. I haven't read the source of the seven, so I can't say which of them do that. Choose "The field alone" under the menu to see what the filter does to the labels here.</p>
<p>A canvas can do the two steps to its own pixels and then draw the elements a second time. On each <code>paint</code> event:</p>
<ol>
<li>The page draws everything that should join: the elements with <code>drawElementImage()</code>, and plain circles and rounded rectangles for the parts that have no element.</li>
<li>The library copies the canvas into a small plain canvas with <code>drawImage()</code> through <code>ctx.filter = 'blur(8px)'</code>. An element's picture can only be drawn into its own canvas, so the copy is of the canvas and not of the elements.</li>
<li>It clears the canvas and draws the copy back through an SVG filter that multiplies alpha by 24 and subtracts 11.5. That is the joined outline, filled with the blurred colours.</li>
<li>With <code>globalCompositeOperation = 'source-atop'</code> the page draws the elements again. They appear only where the outline is, and they are sharp.</li>
</ol>
<p>The last draw of an element is where its hit box is, so a link that is 72 pixels above the dock, in mid-air, is tapped where you see it. Each link moves by one translate and one scale. Nothing here bends an element, which is why input keeps working.</p>
<p><b>The button</b> is one element. Its box is wider than the pill, and the canvas moves a disc with an arrow through the spare space. The disc isn't an element, and it doesn't need to be: a tap on it is a tap on the button.</p>
<p><b>The dock</b>'s <code>&lt;nav&gt;</code> isn't drawn at all. The canvas draws the bar, and a disc under each link that rises with the pointer. The link with <code>aria-current</code> is a bulge in the accent colour. A tap sends a link up far enough to break away, and it falls back and joins the bar again.</p>
<p><b>The menu</b> is a <code>&lt;details&gt;</code>. The summary and each button have <code>drawable</code>, so the canvas can draw each one between the summary and its place in the layout. Closing is the awkward part. A closed <code>&lt;details&gt;</code> has no boxes for its content and <code>drawElementImage()</code> throws, so the page cancels the click that would close it, runs the items back, and then sets <code>open = false</code>. Escape does the same.</p>
<p><b>What was pressed.</b> The states are CSS on the elements: <code>:active</code> darkens a pill, <code>details[open]</code> darkens the summary and turns its arrow, and the item chosen last keeps a tick. A change of style raises a <code>paint</code> event, so the canvas doesn't track any of it.</p>
<p>With reduced motion on, the shapes still join and nothing animates.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 the whole effect is four 2D calls. <code>ctx.filter</code> takes an SVG <code>feColorMatrix</code> by <code>url(#id)</code> and applies it to <code>drawImage()</code>, which gives a threshold on alpha with no shader and no pixel read.</li>
<li><code>drawImage()</code> of a drawable canvas inside its own <code>paint</code> handler copies the element pictures drawn earlier in that handler.</li>
<li><code>source-atop</code> clips a <code>drawElementImage()</code> to what is already on the canvas. The label inside the joined shape is the element's own picture: the check below compares it with a plain draw.</li>
<li>A <code>&lt;summary drawable&gt;</code> and <code>&lt;button drawable&gt;</code> elements inside one <code>&lt;details&gt;</code> draw one by one while it's open. The buttons throw once it has closed.</li>
<li>The threshold eats anything thin. A focus ring drawn outside an element's box disappears, so the rings here are drawn inside the pills with a negative <code>outline-offset</code>. A shape narrower than about twice the blur shrinks or vanishes.</li>
<li>The colours in a neck between two shapes are the blur of both. Where a label sits near the edge of its element, a trace of its colour can show in the neck.</li>
<li>The blurred copy is one pixel per CSS pixel whatever the screen's scale, and the threshold is applied at full size. I haven't seen a soft edge from that at scale 2.625 in the test browser.</li>
<li>Not verified: the frame rate on a phone. The line under the Draw menu reports the paints in the last animation on the device you're using. Also not verified: what a screen reader says. The elements and their states are the native ones, and the disc and the bar are decoration.</li>
<li>Not built: the shader route, and a real <code>popover</code> for the menu. An open popover that is a child of a canvas can't be drawn (<a href="https://html-in-canvas.page/blocked/">/blocked/</a>).</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/liquid-shapes.md">findings/liquid-shapes.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, 412 px wide, device scale 2 and 2.625, mouse and touch emulation) on 2026-11-23. Not yet run on A159.</p>
<p>The page comes from the weekly search for interface work (<code>docs/ui-watch/2026-11-23.md</code>, "Liquid shapes"). The ideas are Kopp's Liquid Arrow Button and Liquid UI Components, Matt Ölschlegel's Reshaping Dock and Manoela Ilic's Gooey Sticky Menu. The page links to each. The code and the copy are mine: I didn't read their source.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A threshold on alpha in a 2D canvas with no shader and no pixel read</td><td>works</td><td><code>ctx.filter = 'url(#id)'</code> with one <code>feColorMatrix</code> (alpha times 24, minus 11.5) applies to <code>drawImage()</code>. A blurred edge that read 72 at 5 px outside and 194 at 5 px inside reads 0 and 255 after it.</td></tr>
<tr><td>Copy the drawable canvas inside its own <code>paint</code> handler</td><td>works</td><td><code>drawImage(canvas)</code> into a plain canvas, straight after <code>drawElementImage()</code>, holds the element pictures. The plain canvas is never read.</td></tr>
<tr><td>Two elements 8 px apart join through blur 8 and the threshold. One 32 px away stays apart</td><td>works</td><td>Live check: 0% ink in the near gap with no field, 100% with it, 0% in the far gap.</td></tr>
<tr><td>Draw the elements a second time inside the joined outline</td><td>works</td><td><code>globalCompositeOperation = 'source-atop'</code> clips <code>drawElementImage()</code> to what is already on the canvas.</td></tr>
<tr><td>The label in the joined shape is the element's own picture</td><td>yes</td><td>Mean pixel difference from a plain draw of the label: 0.00 with the second draw, 19.12 for the field alone (out of 255).</td></tr>
<tr><td>Hit testing after the field</td><td>follows the last draw</td><td>A button drawn 60 px from its layout place is returned by <code>elementFromPoint()</code> there and not at its layout place. A dock link drawn above its layout place takes a tap where it is drawn.</td></tr>
<tr><td><code>&lt;summary drawable&gt;</code> and <code>&lt;button drawable&gt;</code> elements inside one <code>&lt;details&gt;</code></td><td>draw one by one while it is open</td><td>Each can be drawn at a place and scale of the page's choosing.</td></tr>
<tr><td>A button inside a closed <code>&lt;details&gt;</code></td><td>throws</td><td><code>InvalidStateError</code>: "No cached paint record for element". Same as <code>/accordion/</code>. The page cancels the click that would close the menu, runs the items back and then sets <code>open = false</code>.</td></tr>
<tr><td>Keyboard</td><td>works</td><td>Enter on the summary opens and closes, Tab reaches the items while they are open, Enter on an item chooses it, Escape closes and returns focus to the summary. Enter on a dock link makes it current. Space presses the button.</td></tr>
<tr><td>Reduced motion</td><td>shapes join, nothing animates</td><td>The springs jump to their targets.</td></tr>
<tr><td>No API</td><td>plain HTML</td><td><code>mount()</code> from <code>lib/stage-2d.js</code> shows the three controls as ordinary elements. The menu opens and closes as a plain <code>&lt;details&gt;</code>.</td></tr>
<tr><td>The blurred copy at one pixel per CSS pixel, threshold at full size</td><td>no soft edge seen at scale 2.625</td><td>The copy is a seventh of the pixels of the canvas at that scale.</td></tr>
<tr><td><code>npm run check:jank</code></td><td>passes</td><td>cls 0, no flashes, 0 reads, 14.6 MB in canvases.</td></tr>
<tr><td>Paints during an animation in the test browser</td><td>60 a second</td><td>Software rendering on a desktop CPU. It says nothing about a phone.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>I named the wrapper inside each canvas <code>in</code>. The "About this experiment" box that <code>shared/learn.js</code> adds uses the same class for its body, so my <code>display: flex</code> rule laid its paragraphs out as five columns. Paul's screenshot on 2026-11-23 showed it at desktop width, where the box starts open. I had only looked at phone width, where it starts closed. The wrapper is now <code>pool</code>. Look at a new page at both widths.</li>
<li>I gave the canvases the class <code>stage</code>. <code>shared/style.css</code> has a <code>.stage</code> rule with 12 px of padding. <code>mount()</code> takes the scale from <code>canvas.width / canvas.clientWidth</code>, and <code>clientWidth</code> includes padding while the drawing buffer doesn't, so everything was drawn 6% small and the hit boxes were 12 px away from the pictures. Taps on the dock went to the wrong link. A drawable canvas that uses <code>mount()</code> must have no padding.</li>
<li>The threshold removes thin things. A focus ring outside an element's box, 2 px wide, is gone after the cut, and <code>source-atop</code> then clips the second draw of it. The rings on this page are inside the pills (<code>outline-offset: -5px</code>).</li>
<li>A check that sampled a 20 px column between two round-ended pills found 63% ink: the neck between two round ends is narrower than the pills. The check now samples 6 px at the centre line.</li>
<li>Later menu items pass the earlier ones on their way out. Drawn in document order they covered the items already in place, so they are drawn last item first.</li>
<li>A spring with 16% overshoot sent the last menu item past the bottom of the canvas. The menu uses more damping than the button and the dock.</li></ul>
<h3>Changed after review (2026-11-23)</h3>
<ul><li>The current dock link used to sit above the bar as a detached drop. Paul: "the home icon is just sitting out there doing nothing". It is now a bulge on the bar in the accent colour. A tap sends the link up as a drop for 0.4 s and it falls back and joins.</li>
<li>The menu had no sign of what was pressed. <code>:active</code> now darkens a pill, <code>details[open]</code> darkens the summary and turns its arrow, and the item chosen last keeps a tick and the menu waits 0.3 s before it closes. These are CSS on the elements. The canvas redraws because a style change raises <code>paint</code>.</li>
<li>Each demo has its own "Show the code" listing directly under it. The first version had one listing after all three demos and the controls.</li></ul>
<h3>Not verified</h3>
<ul><li>Frame rate on a phone. Each frame is the element draws twice, one blurred <code>drawImage()</code> into a canvas of CSS-pixel size and one filtered <code>drawImage()</code> back at full size. The page prints the paints per second of the last animation under the Draw menu, so opening it on the phone and tapping each control gives the number.</li>
<li>Whether <code>ctx.filter</code> with an SVG filter is as fast on Android as in the test browser, and whether it holds the canvas on the phone. No read is made, and no canvas has <code>willReadFrequently</code>.</li>
<li>What a screen reader says. The button, links (<code>aria-current</code>, <code>aria-label</code>) and <code>&lt;details&gt;</code> are native. The disc, the arrow and the bar are drawn by the canvas and have no element.</li>
<li>Hover on the dock with a real mouse or pen. Touch has no hover, so on a phone the dock shows only the current link leaving the bar.</li></ul>
<h3>Open ideas</h3>
<ul><li>The shader route: the same field in <code>ElementGL</code>, where the threshold could also give a rim light and a refraction, as the liquid glass finds do.</li>
<li>A real <code>popover</code> for the menu. An open popover that is a child of a canvas can't be drawn (<code>/blocked/</code>), so it would have to be an ordinary element until the pour ends, as <code>/top-layer/</code> does.</li>
<li>The metaball loader (Sasha Birukoff) on a native <code>&lt;progress&gt;</code>.</li>
<li>The punch-out dropdown from the same report: <code>destination-out</code> of the trigger's rectangle in the picker of <code>/select/</code>.</li></ul>
<p><a href="https://html-in-canvas.page/liquid-shapes/">Open Controls that join and split like drops</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>About this site</title>
<link>https://html-in-canvas.page/about/</link>
<guid isPermaLink="true">https://html-in-canvas.page/about/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>about</category>
<category>html-in-canvas</category>
<category>slot</category>
<category>libraries</category>
<description>How this site started as an experiment with &lt;slot&gt; inside &lt;canvas&gt; and grew into a set of demos showing what the HTML-in-canvas API can do.</description>
<content:encoded><![CDATA[<p>
This site started with one narrow question about <code>&lt;slot&gt;</code> inside <code>&lt;canvas&gt;</code>, and turned
into a set of demos of what becomes possible when live HTML can be drawn anywhere a pixel can go.
</p>
<p><a href="https://html-in-canvas.page/about/">Open About this site</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Blocked ideas, tested: a picker in a scene, PDF pages, cross-origin pictures, a popover, a permission button and an overscroll drawer</title>
<link>https://html-in-canvas.page/blocked/</link>
<guid isPermaLink="true">https://html-in-canvas.page/blocked/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>select</category>
<category>embed</category>
<category>iframe</category>
<category>img crossorigin</category>
<category>popover</category>
<category>geolocation</category>
<category>overscroll</category>
<category>drawElementImage</category>
<description>Six ideas the backlog marked as blocked, each tried in your browser beside the routes that could replace it: a select's picker, a PDF, pictures from another origin, a popover, a &lt;geolocation&gt; button and a drawer on the overscroll area.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/blocked/"><img src="https://html-in-canvas.page/blocked/social.jpg" width="1200" height="630" alt="The page &quot;Blocked ideas, tested: a picker in a scene, PDF pages, cross-origin pictures, a popover, a permission button and an overscroll drawer&quot;"></a></p>
<p><strong>Question:</strong> Six ideas were marked as blocked by the browser: a select's picker in a scene, PDF pages, pictures from another origin, a popover in the canvas, a permission button, and a drawer on the overscroll area. Are they still blocked in the browser that opens this page, and which other route works?</p>
<p><strong>Short answer:</strong> In Chromium 157 the picker, the open popover and a drawn permission button are blocked, and each has a route that works: a list box, the same element without the popover attribute, a button laid over the canvas. Cross-origin pictures are drawn when they're loaded with CORS. overscroll-area doesn't exist, and the page measures the pull from touch events. The PDF route couldn't be measured: the test browser has no viewer.</p>
<p>
Six ideas from the backlog were marked as blocked by the browser. Each one is tried here anyway. Every section runs the
blocked route and the routes that could stand in for it, in the browser that opens the page, and says which of them
worked. A route that reads pixels waits for a tap on its Measure button.
</p>
<h3>How it works</h3>
<p>Each demo is a canvas with <code>content="drawable"</code> whose children are ordinary elements. A demo starts when its section comes near the screen. The paint handler draws the elements with <code>drawElementImage()</code> and draws everything else with canvas calls.</p>
<p>A measurement that needs pixels runs after a tap. It copies the canvas into a plain 2D canvas with <code>drawImage()</code> and reads single pixels from the copy. The permission buttons and the overscroll property need no pixels: the browser reports them.</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-22. Not yet run on a phone.</p>
<ul>
<li>Picker in the scene: blocked. With the picker of a customisable select open over the canvas, 0 of 15 points on its rows had the picker's colour in the canvas. A list box (<code>size="5"</code>) drawn with a shear took a touch tap on a row, and the element under a sheared row was its <code>option</code>.</li>
<li>PDF pages: not measured where it matters. The test browser has no PDF viewer (<code>navigator.pdfViewerEnabled</code> is false): 0 of 192 points on each page had the colour of the PDF, the embed drew only its "Couldn't load plugin" text, and a tap in the middle of each page landed on the embed and the iframe. The button measures a browser that has a viewer.</li>
<li>Cross-origin pictures: blocked without CORS, not blocked with it. Three pictures from a second origin loaded and 0 of 3 were in the canvas (alpha 0). The same files with <code>crossorigin="anonymous"</code> and an <code>Access-Control-Allow-Origin</code> header: 3 of 3 (alpha 255). Loading row 2 again with the attribute changed it from 0 to 3.</li>
<li>Popover: blocked. <code>drawElementImage()</code> of an open popover that is a child of the canvas threw <code>InvalidStateError</code> and 0 of 9 points had its colour. The same element with the attribute removed was drawn swinging, and its button took a tap. The open popover was shown on the screen at the place the canvas last gave it (71, 62 from the canvas corner, where <code>updateElementGeometry()</code> had put it), not in the middle of the window.</li>
<li>Permission button: blocked inside the canvas, works over it. The drawn <code>&lt;geolocation&gt;</code> reported <code>isValid</code> false, with <code>intersection_out_of_viewport_or_clipped</code> in the demo and <code>intersection_occluded_or_distorted</code> in the live check. The one positioned over the canvas reported true, went false (<code>intersection_changed</code>) for under 1.6 s after it was moved, and stayed true when turned 4 degrees. A tap on it, with the permission granted to the test browser, gave a position.</li>
<li>Overscroll drawer: <code>CSS.supports('overscroll-area', '--drawer')</code> is false. The page's own measure works by touch: a drag of 120 px past the end of the list read as a pull of 103 px, opened the drawer on release, and didn't scroll the page.</li>
<li>One <code>contextlost</code> event stops the six canvases and shows the elements as plain HTML. Tested by dispatching the event.</li>
<li>Not verified: Chrome 159 on Android for all six, and a desktop Chrome with a PDF viewer.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/blocked.md">findings/blocked.md</a> in the repository.</p>
<p>Backlog group 29 in PLAN.md, ideas 29.1 to 29.6. Measured in headless Chromium 157 (C157) on 2026-11-22 at 412 px wide. The page's five live checks pass there, and <code>node tools/blocked/check.mjs</code> drives the six demos by touch (35 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: six ideas were marked as blocked by the browser. Are they still blocked in the browser that opens the page, and which other route works? Each section of the page runs the blocked route and its replacements and writes the result under the demo. Routes that read pixels wait for a tap.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>29.1: the picker of a base-select <code>&lt;select&gt;</code>, open over the canvas after <code>showPicker()</code></td><td>blocked: 0 of 15 points on its rows have its colour in the canvas</td><td>The picker is in the top layer.</td></tr>
<tr><td>29.1: <code>&lt;select size="5"&gt;</code> drawn with a shear of -0.16</td><td>works: pixel 0, 200, 0 inside it, <code>elementFromPoint()</code> on a sheared row gives the <code>option</code>, a touch tap chose Blue</td><td>A list box has no picker. Its rows are in its own picture.</td></tr>
<tr><td>29.2: a PDF in <code>&lt;embed&gt;</code> and in <code>&lt;iframe&gt;</code>, each in a drawable block</td><td>not measured: <code>navigator.pdfViewerEnabled</code> is false in the test browser. 0 of 192 points per page have the PDF's colour</td><td>The embed draws its "Couldn't load plugin." text, which is in the picture. A tap in the middle of each page lands on the embed and on the iframe.</td></tr>
<tr><td>29.3: <code>&lt;img&gt;</code> from a second origin, no <code>crossorigin</code> attribute</td><td>blocked: loaded (<code>naturalWidth</code> 40 in the probe), alpha 0 in the canvas, 0 of 3 in the demo</td><td>Left out of the picture. The canvas is not tainted and is told nothing.</td></tr>
<tr><td>29.3: the same file with <code>crossorigin="anonymous"</code> and <code>Access-Control-Allow-Origin: *</code></td><td>works: alpha 255, 3 of 3</td><td>Both live hosts send the header for static files (checked with a request on 2026-11-22).</td></tr>
<tr><td>29.3: knowing which pictures are left out with no readback</td><td>works</td><td>A different origin and <code>img.crossOrigin === null</code>. The wall draws the alt text on a hatched card there.</td></tr>
<tr><td>29.4: <code>drawElementImage()</code> of an open popover that is a child of the canvas</td><td>blocked: throws <code>InvalidStateError</code>, 0 of 9 points drawn</td><td></td></tr>
<tr><td>29.4: the same element with the <code>popover</code> attribute removed</td><td>works: drawn rotated on a string, its button took a tap</td><td>The demo moves one card between the two homes. A light dismiss returns it to the scene through the <code>toggle</code> event.</td></tr>
<tr><td>29.4: where the open popover is shown</td><td>at the place the canvas last gave it: 71, 62 from the canvas corner after <code>updateElementGeometry()</code></td><td>Before that call was added, the popover was shown turned, as the canvas had last drawn it. <code>position: fixed; inset: 0; margin: auto</code> did not centre it.</td></tr>
<tr><td>29.5: <code>&lt;geolocation&gt;</code> drawn by the canvas, flat, full size</td><td>blocked: <code>isValid</code> false. <code>invalidReason</code> was <code>intersection_out_of_viewport_or_clipped</code> in the demo and <code>intersection_occluded_or_distorted</code> in the live check and the first probe</td><td></td></tr>
<tr><td>29.5: <code>&lt;geolocation&gt;</code> outside the canvas, positioned over it</td><td>works: <code>isValid</code> true</td><td>The canvas draws a ring round its rectangle from <code>isValid</code>.</td></tr>
<tr><td>29.5: the overlay moved by 72 px</td><td>false (<code>intersection_changed</code>) 0.1 s later, true again within 1.6 s</td><td></td></tr>
<tr><td>29.5: the overlay with <code>transform: rotate(4deg)</code>; <code>scale(1.3)</code>; <code>opacity: .8</code>; <code>filter: hue-rotate()</code></td><td><code>isValid</code> true for each</td><td>Probe, one element at a time. <code>font-size: 8px</code> and a light grey text colour gave <code>style_invalid</code>.</td></tr>
<tr><td>29.5: the overlay under a <code>pointer-events: none</code> block</td><td>false (<code>intersection_occluded_or_distorted</code>), true again when the block is removed</td><td>So the canvas cannot draw over the button. It draws round it.</td></tr>
<tr><td>29.5: a touch tap on the overlay with the permission granted to the test browser</td><td>a <code>location</code> event with a position (accuracy 25 m, the test value)</td><td>The prompt itself is not shown in headless Chromium.</td></tr>
<tr><td>29.6: <code>CSS.supports('overscroll-area', '--drawer')</code></td><td>false</td><td><code>overscroll-behavior: contain</code> is supported.</td></tr>
<tr><td>29.6: the pull measured by the page</td><td>works by touch: a drag of 120 px past the end read as 103 px, the drawer opened on release, the page did not scroll</td><td><code>touchmove</code> events keep arriving while a drawable scroller scrolls natively and after it stops at its end.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the six canvases (6 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Nine <code>&lt;geolocation&gt;</code> elements on one probe page: six stayed at <code>unsuccessful_registration</code>. One at a time, each registered. The demo has two.</li>
<li>The first PDF measurement counted the shade the canvas draws on the fold as PDF ink (8 of 48 points). The measurement now draws one frame without the shade and looks for the colour of a band that is in the file.</li>
<li>An <code>&lt;embed type="application/pdf"&gt;</code> with no <code>src</code> already shows "Couldn't load plugin." The type is now set with the <code>src</code>, on the tap.</li>
<li>The first drag test opened the drawer early: a drag that reaches the end of the list keeps counting as a pull.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: all six demos by touch.</li>
<li>29.2 on any browser with a PDF viewer. Desktop Chrome has one. Tap "Load the PDF and measure" there and read the two lines under the book.</li>
<li>Whether Chrome on Android offers to download the PDF when the button is tapped.</li>
<li>The picker of a customisable select on a phone: it may be a native sheet, which changes what "open over the canvas" means.</li>
<li>The real permission prompt after a tap on the overlaid button, and whether a canvas repaint under the button makes it invalid on a real GPU.</li>
<li>The wall between the two live hosts (<code>html-in-canvas.page</code> and the workers.dev host). The test used <code>localhost</code> and <code>127.0.0.1</code>.</li>
<li>The pull with a real finger, where the browser's own overscroll glow or stretch may also show.</li></ul>
<h3>Open ideas</h3>
<ul><li>29.2 with a JavaScript PDF renderer drawing into a canvas inside the drawable page, to compare with the embed.</li>
<li>A permission button with a scene drawn round it that reacts to <code>permissionStatus</code>.</li></ul>
<p><a href="https://html-in-canvas.page/blocked/">Open Blocked ideas, tested: a picker in a scene, PDF pages, cross-origin pictures, a popover, a permission button and an overscroll drawer</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Per-element themes</title>
<link>https://html-in-canvas.page/canvas-skin/</link>
<guid isPermaLink="true">https://html-in-canvas.page/canvas-skin/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>custom element</category>
<category>drawElementImage</category>
<category>shadow DOM</category>
<category>ctx.filter</category>
<category>themes</category>
<description>Every button, field, checkbox, slider, table and heading on a booking form is wrapped in its own small canvas by &lt;canvas-skin&gt;. A theme switch changes all of them between 29 skins, among them refracting glass, pencil, a thermal camera, a neon sign, embroidery, brushed metal, a comic with halftone dots, 1-bit pixels, typed ASCII characters, blocks in perspective, an oil painting lit from the last touch, and one where each element bends its neighbours like a heavy object bends light, one after another outward from the tap.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/canvas-skin/"><img src="https://html-in-canvas.page/canvas-skin/social.jpg" width="1200" height="630" alt="The page &quot;Per-element themes&quot;"></a></p>
<p><strong>Question:</strong> Can a page be themed by wrapping each element in a small drawable canvas of its own, instead of drawing the whole page with one canvas, and do the wrapped controls still take input?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157, with one 2D context per element. The shader skins share one WebGL context on a canvas outside the document and copy its output with drawImage().</p>
<p>
The form below is ordinary HTML. A script puts each heading, paragraph, image, field, checkbox, slider, table and button inside a
<code>&lt;canvas-skin&gt;</code> element, which holds a small drawable canvas that draws that one element. No canvas covers the page.
Choose a skin in the bar at the bottom of the form: every wrapper changes, starting with the ones nearest to your finger. The skins are
in four groups, and Options opens the settings of the skin that is showing. The controls are the real ones. Type in the fields, tick
the boxes and drag the slider in any skin.
</p>
<h3>How it works</h3>
<ul>
<li><b>One canvas per element.</b> The shadow root of <code>&lt;canvas-skin&gt;</code> holds <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> with one <code>drawable</code> <code>&lt;div&gt;</code> that contains a <code>&lt;slot&gt;</code>. The wrapped element is slotted, so it stays in the page's DOM, in its form and in the accessibility tree, and the page's CSS still styles it.</li>
<li><b>The wrapper has the element's size.</b> The canvas is positioned 14 px outside the wrapper on every side, which gives a skin room for a shadow or a line that overshoots. The canvas has <code>pointer-events: none</code> and the slotted element has <code>pointer-events: auto</code>, so the extra 14 px never takes a tap that belongs to a neighbour.</li>
<li><b>A skin is CSS plus a paint function.</b> The CSS sets the font and colours and removes the browser's own drawing of a control (<code>appearance: none</code>, no border, no background). The paint function draws the surface, then the element's own picture with <code>drawElementImage()</code>, sometimes through an SVG filter set as <code>ctx.filter</code>.</li>
<li><b>Checkboxes, radios, switches, sliders and progress bars are drawn from their state.</b> For these the skin never draws the element's picture. It reads <code>checked</code> or <code>value</code> and draws the whole control. The native control is still drawn once per paint inside an empty clip, which puts its hit region where it lies in the layout and adds no pixels.</li>
<li><b>The glass skin is a shader that every wrapper shares.</b> The page background is a set of CSS gradients with straight diagonal lines, and the skin has the same picture as canvas calls. For each glass element it draws the part of that picture behind the element into a plain canvas, uploads it as a texture to one WebGL context on a canvas that isn't in the document, runs the shader, and copies the result into the element's own 2D canvas with <code>drawImage()</code>. The shader computes a signed distance to the element's rounded rectangle, a surface height from it, the surface normal from the slope, and <code>refract()</code> for red, green and blue.</li>
<li><b>One 2D context per element, and one WebGL context for the page.</b> An element's picture can be drawn only by a canvas the element is inside, so the wrappers can't share a WebGL context for their own pictures, and Android allows about 8 WebGL contexts in a tab. The glass shader can be shared because its input is the background, which is an ordinary canvas. The element's own picture (its text) is drawn over the glass in 2D. The effects of the other skins are SVG filters. A wrapper that is more than one screen away sets its canvas to 0 by 0.</li>
<li><b>The glass sees the root's background and nothing else.</b> A canvas can't read the pixels behind it, so a glass element doesn't refract another element that lies under it. Glass over arbitrary content needs that content as a texture, which is the one-canvas-for-the-page design this page avoids.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-22, at 412 px wide and device scale 2, with WebGL rendered in software. Not yet run on a phone.</p>
<ul>
<li><b>One WebGL context can serve every wrapper when its input isn't an element.</b> The glass shader ran for 31 elements at load from one context, with a <code>texImage2D()</code> of a sub-rectangle of a 2D canvas and a <code>drawImage()</code> of the WebGL canvas for each. The WebGL route has no WebGPU version yet.</li>
<li><b>A page can be themed with one small drawable canvas per element.</b> The form has 32 wrappers, and the page has 53 with the tiles and the nested card. Each control took taps, clicks and typing at its place in the layout in every skin.</li>
<li><b>A child of a drawable canvas is as wide as its content.</b> A block <code>&lt;div&gt;</code> directly inside <code>&lt;canvas layoutsubtree&gt;</code> didn't fill the canvas: a heading in it was 211 px wide in a 380 px canvas. It needs an explicit width.</li>
<li><b>A block wrapper has no width of its own.</b> Its only in-flow content is the box that holds the canvas, so in a place that sizes to content (a flex row, a grid cell with <code>justify-items: start</code>) it is 0 px wide and gets no paint event. Wrappers of buttons, checkboxes, radios, switches, labels and outputs are inline and take the element's own width. The others need a container that gives them a width.</li>
<li><b>The change of skin moves nothing.</b> Every skin gives each kind of element the same box (a 44 px button, a 28 px checkbox), so only fonts change the layout, where text wraps differently.</li>
<li><b>Memory.</b> At 412 px wide and device scale 2.625 the page's estimate was 12.6 MB for all canvases, and the largest canvas was 0.55 megapixels. Thirty wrapped buttons were 99 KB each at scale 2.</li>
<li><b><code>pointer-events: none</code> on the canvas and <code>auto</code> on its child leaves the child hit-testable.</b> <code>elementFromPoint()</code> at the centre of a wrapped button returned the button, and a point in the canvas's extra 14 px returned what lies under the canvas.</li>
<li><b>A control that is never painted still works.</b> A checkbox and a range drawn only inside an empty clip toggled on a tap and followed a drag.</li>
<li><b>A wrapper inside a wrapper drew and took input</b> in this browser. <a href="https://html-in-canvas.page/nested-frames/">/nested-frames/</a> has a report of nested canvases that didn't draw on Chrome 159 for Android, so this needs the phone.</li>
<li><b>A paint handler can return without drawing.</b> The canvas keeps the picture it had. The wrappers use this to spread the paints of a change of skin over several frames: with the CPU slowed 4 times at device scale 2.625, a change to the stained glass skin drew 46 frames in 2.4 seconds with the frame budget and 6 without it. These are software-rendered numbers. The line under the form gives this device's.</li>
<li><b>An SVG filter in the wrapper's shadow tree follows a CSS variable set on the wrapper.</b> The oscilloscope's line filter takes its colour from <code>style="flood-color: var(--beam)"</code>.</li>
<li><b>Not verified:</b> everything on a phone. In particular how many small 2D canvases Chrome for Android keeps (31 had pixels at once at the top of this page), the speed of a change of skin when 20 wrappers fade at once, the SVG displacement filter of the pencil skin on every wrapper, the native picker of the wrapped <code>&lt;select&gt;</code>, and what a screen reader reads.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/canvas-skin.md">findings/canvas-skin.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) on 2026-11-22, at 412 px wide, device scale 2 and 2.625, with taps sent as touch events. Not run on a phone.</p>
<p><code>&lt;canvas-skin&gt;</code> wraps one element in a small drawable 2D canvas. A <code>skin</code> attribute on an ancestor chooses how every wrapper under it draws. 29 skins are built in: glass, pencil, gel, terminal, blueprint, thermal camera, neon sign, embroidery, Christmas, seaside, LED board, punch card, oscilloscope, X-ray, 1-bit, ASCII, comic, 3D blocks, stained glass, clay, brushed metal (aluminium, steel, brass, copper, chrome), underwater, gravity, holographic foil, screen print, crayon, impressionist, old master and native (the browser's own drawing).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Can a page be themed with one drawable canvas per element instead of one canvas for the page?</td><td>Yes (measured). 53 wrappers on the page, 32 of them in the form.</td><td>Shadow root: <code>&lt;canvas content="drawable" layoutsubtree&gt;&lt;div drawable&gt;&lt;slot&gt;&lt;/slot&gt;&lt;/div&gt;&lt;/canvas&gt;</code>. The element is slotted and stays in the page's DOM.</td></tr>
<tr><td>Do the wrapped controls take input?</td><td>Yes (measured). Tap on a checkbox, click on a range, label click, typing, form data.</td><td>The canvas has <code>pointer-events: none</code>, the drawable <code>&lt;div&gt;</code> has <code>pointer-events: auto</code>. <code>elementFromPoint()</code> at a button's centre returns the button.</td></tr>
<tr><td>Does the canvas's extra 14 px on each side take hits from neighbours?</td><td>No (measured).</td><td>A point 6 px outside a wrapped button, over its canvas, returned the element under the canvas.</td></tr>
<tr><td>Can a skin draw a control from its state without painting the native control?</td><td>Yes (measured) for checkbox, radio, switch, range, progress.</td><td>The native control is drawn once per paint inside an empty clip. It toggled on <code>click()</code> and on a tap, and a click at 80% of a range set 82.</td></tr>
<tr><td>Is a block <code>&lt;div&gt;</code> inside <code>&lt;canvas layoutsubtree&gt;</code> as wide as the canvas?</td><td>No (measured). It is as wide as its content: a heading was 211 px in a 380 px canvas.</td><td>It needs <code>width: calc(100% - 28px)</code>.</td></tr>
<tr><td>Does a wrapper inside a wrapper draw and take input?</td><td>Yes (measured in C157).</td><td>The outer canvas had the inner button's pixels, and the point found the <code>&lt;button&gt;</code>. <code>/nested-frames/</code> has a report of nested canvases not drawing on A159.</td></tr>
<tr><td>Can the wrappers share one WebGL context?</td><td>Not to draw elements (inferred from <code>findings/</code> results on <code>ElementImage</code> and <code>texElementSubImage2D()</code>: an element is drawn only by a canvas it is inside). Yes for pixels that are not an element (measured, headless Chromium 157, 2026-11-22).</td><td>The elements are drawn by 2D canvases, with SVG filters used as <code>ctx.filter = 'url(#id)'</code> in each wrapper's shadow root. The glass skin uses one WebGL2 context on a detached canvas (<code>lib/glass-gl.js</code>): each glass element sends the part of the background copy that lies behind it as a texture, the shader runs, and the wrapper copies the result with <code>drawImage()</code>.</td></tr>
<tr><td>Can a glass skin show the page background through an element?</td><td>Yes, when the background is known to the skin (the live check "The glass shader bends the background" compares refractive index 1.5 with 1).</td><td>The canvas cannot read what is behind it. The skin has the root's CSS gradients and diagonal lines again as canvas calls and draws them into a shared plain canvas. The shader treats the element as a slab with a rounded rim: signed distance to the rounded rectangle, surface height and normal, <code>refract()</code> once each for red, green and blue, an 8-tap blur for frost, highlights from a light direction. Settings: light angle, rim width, thickness, refractive index, dispersion, frost, highlights, tint. Five modes are sets of these values (Regular, Clear, Frosted, Thick lens, Prism); the values are this page's, not Apple's. Without WebGL, or after the shared context is lost, glass is drawn in 2D as 12 enlarged rings. No check exercises the 2D version after a real loss.</td></tr>
<tr><td>How is a change of skin animated?</td><td>Each wrapper copies its canvas with <code>drawImage()</code> into a plain canvas, switches, and fades the copy out over the new drawing in 640 ms (measured: order 10, 130, 323 ms for three buttons at 0.3 px per ms).</td><td><code>CanvasSkin.apply(root, name, { x, y })</code> gives each wrapper a delay by distance from the point. The root's old background stays on a layer whose mask has a growing hole.</td></tr>
<tr><td>What does it cost?</td><td>18.8 MB for all canvases by the guard's estimate at scale 2.625 (<code>npm run check:jank</code>, 2026-11-22), largest canvas 0.67 MP, 1 WebGL context. 30 wrapped buttons: 99 KB each at scale 2 (measured).</td><td>Wrappers more than one screen away set their canvas to 0 by 0. The WebGL context is made when the first glass element paints, which is at load on this page because it opens in glass.</td></tr>
<tr><td>What happens after a lost context?</td><td>The wrapper moves the element out of the canvas and sets <code>plain</code> (measured with a dispatched <code>contextlost</code> event).</td><td>The element then has the skin's font and colours and a CSS border.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A block wrapper has no intrinsic width, because its only in-flow content is the box that holds the canvas. In a flex row or a grid cell with <code>justify-items: start</code> it was 0 px wide and got no paint event. Wrappers of buttons, checkboxes, radios, switches, labels and outputs are inline and are sized from the element.</li>
<li>Glass background: a CSS gradient tile cuts each blob at the tile's edge. The seam showed in the page and in the canvas copy until each blob was listed three times, one tile apart.</li>
<li><code>ResizeObserver</code> on the canvas as well as on its child would report a loop error, because the canvas is the child's ancestor. The wrapper observes the child only and computes the canvas size from it.</li>
<li>Reported from A159 on 2026-11-22, three times in one visit: "ResizeObserver loop completed with undelivered notifications". The wrapper wrote its box size inside the observer callback, which resizes other observed elements (the outer wrapper of a nested pair, a neighbour in a flex row). The sizes are now read and written in one animation frame for all wrappers. The error did not occur in C157 before or after, so the fix is not verified.</li>
<li>Playwright's <code>setViewportSize()</code> resets a forced device scale factor to 1.</li></ul>
<h3>Skins added on 2026-11-22 (headless Chromium 157)</h3>
<table><thead><tr><th>Question</th><th>Answer</th><th>How</th></tr></thead><tbody><tr><td>Can a skin work on the pixels of the element's picture?</td><td>Yes (seen in screenshots, no live check yet).</td><td><code>grab()</code> in <code>lib/canvas-skin-draw.js</code>: the wrapper's canvas draws the element, the whole canvas is copied into a plain canvas with <code>drawImage()</code>, and the wrapper's canvas is cleared. The embroidery skin draws that copy small and enlarges it with no smoothing, then uses a repeated cross as a <code>destination-in</code> mask. The sea skin gives the copy to a shader as a texture.</td></tr>
<tr><td>Can other shaders use the glass skin's WebGL context?</td><td>Yes. <code>check:jank</code> counts 1 WebGL context with glass, metal, sea and space all on the page.</td><td><code>shade(name, body, panel, scale, values, source, copy)</code> in <code>lib/glass-gl.js</code> compiles a program per name in the same context. Each call is one pass into the shared canvas and one <code>drawImage()</code> into the wrapper.</td></tr>
<tr><td>Can a skin animate without painting every frame?</td><td>Yes.</td><td>A skin sets <code>frame.wait</code> to a number of milliseconds and the wrapper asks for its next paint after that time. The sea skin uses 50 ms.</td></tr>
<tr><td>Can a skin use where the page was touched?</td><td>Yes (seen in screenshots after synthetic pointer events, no live check yet).</td><td>The thermal skin listens for <code>pointerdown</code> and <code>pointermove</code> on the document, keeps the last 40 points for 4.5 seconds, and asks the wrapper under the pointer to paint.</td></tr></tbody></table>
<p>| Can an element be drawn bent by the elements round it? | Yes, inside its own canvas (seen in screenshots). | The gravity skin measures every wrapper at most once in 0.8 s, gives each a mass from its size, and gives the shader the four that pull hardest on this element and the pointer. A wrapper cannot draw outside its canvas, so the displacement is capped at 13 px (the canvas has 14 px of room). The page background is CSS and is not bent. |</p>
<p>| Does a sensor reach a skin? | Written, not verified: headless Chromium sends no <code>deviceorientation</code>. With a mouse the same code follows the pointer. | Foil and metal move their highlight with tilt. The wrappers are painted again at most 12 times a second and only when the tilt changed by more than 0.02. |</p>
<p>| Does the shader need the element's picture each frame? | No. | <code>shade()</code> keeps one texture per element when given <code>keep</code> and <code>sig</code>. The underwater skin skips the 2D drawing, the copy and the upload while only the water moves. |</p>
<p>Owner's notes from the phone, 2026-11-22 (Chrome 159, Android): the first underwater skin was "pretty slow". It drew, copied and uploaded every near wrapper 20 times a second. It now uploads only on change, paints 15 times a second on screen and 2 off it. Not measured again on the phone. The first space skin (a ring of bent stars round each box over tiled dot stars) and the first metal skin (chrome with a horizon) were not liked, and were replaced by gravity and brushed metal.</p>
<p>Problems met: LED lamps 3 px apart made 16 px text unreadable, and 2 px apart reads as a dot-matrix sign. Dark lettering over the lead lines of the stained glass was unreadable until an SVG filter put a pale ground round each letter. A grain of 0.6 on the metal normal made the reflection unreadable noise and hid the field text; 0.07 reads as brushing. A cross-stitched heading at 2.2 px cells was not legible, so only pictures are cross-stitched and text is drawn through a lighting filter.</p>
<h3>Third round, 2026-11-22 (headless Chromium 157)</h3>
<p>The owner reported from the phone (Chrome 159, Android) that the change of skin had become "really slow", that the oscilloscope showed no difference between states, that old master "didn't really work", that stained glass was "really hard to see anything in" and that clay was not exciting. <code>npm run reports -- --since 3h --list --page /canvas-skin/</code> at 11:17 showed nine "ResizeObserver loop completed with undelivered notifications" errors from three visits, 66 to 69 minutes old, and no lost context, crash or shader report.</p>
<table><thead><tr><th>Question</th><th>Answer</th><th>How</th></tr></thead><tbody><tr><td>Can the wrappers limit how much they paint in one frame?</td><td>Yes. With the CPU slowed 4 times at device scale 2.625, a change to the stained glass skin went from 6 frames in 2.4 s to 46, old master from 7 to 33, screen print from 6 to 55, pencil from 8 to 45 (<code>perf.mjs</code>, a scratch script that counts <code>requestAnimationFrame</code> gaps after a click). These are software-rendered numbers and say nothing about the phone.</td><td><code>ask()</code> and <code>run()</code> in <code>lib/canvas-skin.js</code>. Paints that follow a paint are asked for by one loop. Each frame it asks the wrappers that waited longest until their last paints' script time adds up to a budget (6 ms at first). A late frame multiplies the budget by 0.7 (not below 1.5 ms) and a frame on time by 1.06 (not above 8 ms). Entrances are timed by the clock, so a wrapper that waits skips ahead.</td></tr>
<tr><td>Can a wrapper decline a paint event the browser raises?</td><td>Yes. A paint handler that returns without drawing leaves the canvas with the picture it had.</td><td>A change of skin changes the CSS of every wrapper, so the browser raises <code>paint</code> for all of them in one frame. When that frame's paints have already taken twice the budget, the handler returns and joins the loop. It never declines the first paint or a paint after the canvas was resized, which would show an empty canvas.</td></tr>
<tr><td>Which wrappers animate?</td><td>Only those in the window.</td><td><code>apply()</code> reads each wrapper's box. A wrapper outside the window (but within one screen, so it has a canvas) changes at once with no copy of its old picture and no entrance.</td></tr>
<tr><td>What did the old root background cost?</td><td>The first change away from the glass skin had one gap of about 700 ms in the slowed test browser, with or without the mask. It is the raster of a second layer with the glass background, not script (the long animation frame had under 80 ms of script). Not measured on a phone GPU.</td><td>The layer with the old background had a <code>mask-image</code> whose radius was an animated registered property. It is now two layers: the old background, cut with <code>clip-path: inset()</code> to the part in the window, and the new one with an animated <code>clip-path: circle()</code>. The soft 70 px edge of the mask is gone.</td></tr>
<tr><td>What does the page report about a change?</td><td>Frames drawn and missed, the longest gap, the number and script time of element paints, paints put off, the budget, the <code>event</code> timing entry of the tap and the <code>long-animation-frame</code> entries.</td><td><code>measure()</code> in <code>public/canvas-skin/page.js</code>. The same numbers go to the report endpoint as type <code>skin-change</code>, so <code>npm run reports -- --page /canvas-skin/</code> shows what the phone measured.</td></tr>
<tr><td>Can a skin have options?</td><td>Yes. Live check "CanvasSkin.set() changes an option of a skin".</td><td>A skin gives <code>settings</code>, <code>options</code> (numbers with a range, or choices), optional <code>presets</code>, and <code>vars(settings)</code> for CSS custom properties. <code>CanvasSkin.set(name, values)</code> writes them and repaints that skin's wrappers. The page builds one panel from the list. 15 skins have options.</td></tr>
<tr><td>Can an SVG filter in the wrapper's shadow tree read a CSS variable of the skin?</td><td>Yes: <code>&lt;feFlood style="flood-color: var(--beam)"&gt;</code> followed the oscilloscope's beam colour (seen in a screenshot). <code>flood-color="var(--beam)"</code> as an attribute does not.</td><td>The variable is set on the wrapper by the skin's rule and inherits into the shadow tree.</td></tr>
<tr><td>Can a picture be turned into characters without reading pixels each paint?</td><td>Yes.</td><td>The ASCII skin draws the element's picture into a plain canvas with one pixel per character, made with <code>willReadFrequently</code>, reads it once and keeps the rows of characters until the picture's size or source changes. <code>check:gfx</code> allows the read with a <code>gfx-allow</code> comment.</td></tr>
<tr><td>Can a 2D canvas draw an element as a block in perspective that follows scrolling?</td><td>Yes (seen in screenshots at two scroll positions).</td><td>The 3D blocks skin keeps the face at the layout position and draws the back and two sides toward the middle of the window. A <code>scroll</code> listener asks every wrapper in that skin to paint through the frame budget.</td></tr></tbody></table>
<p>First numbers from the phone (Chrome 159, Android, device scale 3, 83 wrappers, 2026-11-22 11:46, <code>skin-change</code> reports): LED board to oscilloscope 97 frames drawn and 3 missed in 1.6 s; terminal to LED board 79 drawn, 26 missed, longest gap 50 ms; glass to gravity 56 drawn, 31 missed, longest gap 117 ms, 272 ms of paint script; gravity to ASCII longest gap 150 ms and 456 ms from the tap to the next frame, with 14 long animation frames of at most 68 ms. Two of the four ended with the budget at its floor of 1.5 ms although paint script was 82 and 100 ms in all: the loop took the shortest gap between two callbacks as the screen's frame time, so ordinary 60 Hz frames counted as late. It now uses the middle of the last 15 gaps, as the nearest common rate. Not measured again on the phone.</p>
<p>More from the phone at 11:52 (same device, after the frame time fix): X-ray to thermal and thermal to punch card missed 0 of 94 and 91 frames; 1-bit to comic missed 4 of 89; glass to X-ray 17 of 94; comic to 1-bit 25 of 93; browser default to gravity 28 of 94 with 164 ms of paint script. The owner called gravity "particularly slow". While a finger moved, every gravity wrapper within 300 px drew its shapes, copied its canvas and uploaded a texture on each frame. The gravity skin now keeps one texture per element as the underwater skin does, asks for those paints through the frame budget, and reaches 190 px. In the test browser 40 pointer moves cost 4.9 ms of script per element paint, 10.1 ms before (software WebGL, device scale 2). Not measured on the phone.</p>
<p>What changed in the skins: the oscilloscope's shapes are lists of points, the element with focus (<code>:focus</code>, so also after a tap) has a point with a fading tail running along them, a pressed element is traced twice, and a field becomes a whole box with focus. Old master uses a Kuwahara filter, lit brush ridges, a lamp that also lights the wall through two CSS variables written on the root, and gilded frames drawn after the shader. Stained glass elements are a pale pane with a border of coloured pieces, so text is dark on pale glass. Clay presses the text of a button or field into the surface (the element's picture is the stamp).</p>
<h3>Not verified</h3>
<ul><li>Everything on Chrome 159 for Android: how many small 2D canvases it keeps, the speed of a change of skin with about 20 wrappers fading at once, the pencil skin's SVG displacement filter on every wrapper, the native picker of a wrapped <code>&lt;select&gt;</code>, the on-screen keyboard over a wrapped field, a screen reader. Opening <code>/canvas-skin/</code> on the phone, changing skins and running the checks would verify these. The line under the form reports how many wrappers fell back to plain HTML and why.</li>
<li>Frame rate. The test browser renders in software.</li>
<li>The frame budget on the phone. The numbers above come from a software renderer with the CPU slowed. The line that begins "Change from" under the form, and the <code>skin-change</code> reports, are the phone's own numbers after the next visit.</li>
<li>Whether an animated <code>clip-path: circle()</code> on a full-size layer is cheaper than the animated mask on the phone.</li>
<li>Tilt for the 3D blocks skin (no <code>deviceorientation</code> in the test browser), the speed of repainting every block while scrolling, and the look of the ASCII skin with the phone's monospace font.</li>
<li>The beam running round a focused element after a touch tap on the phone. In the test browser <code>tap()</code> on a field showed it.</li>
<li>The sea skin on the phone: every near wrapper does a canvas copy, a texture upload, a shader pass and a <code>drawImage()</code> 20 times a second. If the phone cannot keep up, raise <code>frame.wait</code> or animate only the element under the pointer.</li>
<li>The no-WebGL versions of metal, sea and space. They are written and no check runs them.</li>
<li>The glass shader on a phone GPU: the cost of one texture upload and one shader pass per glass element per paint, and how dragging a glass slider (every glass element repaints per input event) feels. The line under the form says whether glass is drawn by the shader or the 2D version, and why.</li>
<li>A WebGPU version of the glass shader. The project order is WebGPU, WebGL, 2D; only WebGL and 2D are written.</li>
<li>The "ResizeObserver loop" error reported from the phone on 2026-11-22. Sizes are now applied in one animation frame; the error did not occur in Chromium 157 before or after, so the fix is not confirmed.</li>
<li><code>computedRole</code> was not available in the test browser, so the role check reports only form and label behaviour there.</li></ul>
<h3>Open ideas</h3>
<p>For PLAN.md, how the skins could be made faster or better later (owner, 2026-11-22: "put it in the plan about how we might improve these in the future"):</p>
<ul><li>Speed of a change of skin. On the phone some changes still miss 17 to 28 of about 94 frames (glass to X-ray, comic to 1-bit, default to gravity). To try: compile every shader program when the page is idle, not on a skin's first paint; keep one old-picture canvas per wrapper for its lifetime, not one made per change; fade only the wrappers nearest the tap and switch the rest at once; lower the canvas scale to 2 on a device scale of 3 while a change runs.</li>
<li>Shader skins at rest. Every shader pass is followed by a <code>drawImage()</code> from the shared WebGL canvas into the wrapper's 2D canvas. To try: give underwater, foil, metal and the painting skins the kept texture that gravity and underwater have; run one pass over an atlas of all visible wrappers and cut it up with <code>drawImage()</code>, which is one GPU sync per frame and not one per element.</li>
<li>WebGPU. The project order is WebGPU, WebGL, 2D. <code>shade()</code> and the glass shader are WebGL only. A WGSL version through <code>webgpu()</code> in <code>shared/backend.js</code> is not written.</li>
<li>Measurement. The <code>skin-change</code> report covers the change only. Add a report of frames missed over a few seconds at rest and while a finger moves, per skin, so that a slow skin shows in <code>npm run reports</code> without the owner saying so. The frame rate read from the gaps was wrong twice (144 Hz reported on a 60 Hz phone before the middle-gap fix); check it against the next reports.</li>
<li>Skins the owner judged weak: clay ("not super excited") and old master were reworked once and have not been judged again. Oscilloscope, stained glass and X-ray likewise.</li>
<li>Skins offered and not built: ice, ember, aurora.</li>
<li>Options: 14 skins have none (pencil, gel, terminal, blueprint, thermal, neon, embroidery, Christmas, seaside, LED board, punch card, X-ray, crayon, native).</li>
<li>3D blocks: tilt is not verified on a device. A real perspective (the face smaller toward the back, text on the floor of a field) needs more than the 14 px of room round each canvas.</li></ul>
<ul><li>A skin whose background moves (the glass background drifting) would need every glass wrapper to repaint per frame.</li>
<li>A wrapper could take <code>backdrop</code> from a second canvas that draws the root, to show arbitrary content through glass.</li>
<li><code>CanvasSkin.wrap()</code> could run again from a <code>MutationObserver</code> for elements added later.</li></ul>
<p><a href="https://html-in-canvas.page/canvas-skin/">Open Per-element themes</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Conveyor belt list: an endless list from ten elements, drawn round two rollers</title>
<link>https://html-in-canvas.page/conveyor/</link>
<guid isPermaLink="true">https://html-in-canvas.page/conveyor/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>virtual list</category>
<category>infinite scroll</category>
<category>updateElementGeometry</category>
<category>drawImage</category>
<category>paint event</category>
<category>changedElements</category>
<category>touch</category>
<description>A virtualised list with no end as a conveyor belt. Rows come up round the bottom roller and go over the top one, and ten real elements are reused for every row. Each row has a checkbox and a button that take taps while the belt moves.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/conveyor/"><img src="https://html-in-canvas.page/conveyor/social.jpg" width="1200" height="630" alt="The page &quot;Conveyor belt list: an endless list from ten elements, drawn round two rollers&quot;"></a></p>
<p><strong>Question:</strong> Can an endless list be drawn as a conveyor belt, with rows that come up round a roller and go over another, from a fixed number of real elements that still take taps while they move?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. Ten elements show any row, row 1,000,000 included. Each element is drawn once when its picture changes and copied to a plain canvas, the belt is drawn from the copy in slices, and updateElementGeometry() puts each row's hit box where the row is. A touch drag of 190 px drew 53 frames with 6 element draws.</p>
<p>
A list with no first and no last row, shown as the face of a conveyor belt. Rows come up from underneath round the
bottom roller, travel up the flat face, and go over the top roller to the back. The document holds ten row elements
whatever the position: an element that has gone over a roller is given the content of the next row to arrive.
</p>
<h3>How it works</h3>
<p>The canvas has ten <code>drawable</code> children. Row <i>i</i> of the list is shown by element <i>i</i> mod 10, so an element is refilled only when its row is past the crest of a roller.</p>
<p>Moving the belt doesn't draw any element. Each element's picture is drawn with <code>drawElementImage()</code> once after it changes, copied into a plain canvas with <code>drawImage()</code>, and wiped. A frame of the belt is cut from that copy: one piece for the part of a row on the flat face, and pieces 3 px of belt long round a roller, each drawn shorter, narrower and darker by the angle it has turned.</p>
<p>Because no element is drawn where it appears, the canvas tells the browser where each row is with <code>updateElementGeometry()</code>. That's what lets a tap reach a checkbox on a moving row.</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-22. Not yet run on a phone.</p>
<ul>
<li>Ten elements show any row. At row 1,000,000 and at row -5 the canvas had 10 children, and a tap on the checkbox of row 1,000,002 ticked it.</li>
<li>A tick is kept by row number. Row 4 was still ticked after its element had shown other rows on the way to row 1,000,000 and back.</li>
<li>Moving the belt draws no element. A touch drag of 190 px drew 53 frames and copied 6 element pictures to the atlas. A flick that carried the belt about 740 px drew about 166 frames and copied 18.</li>
<li><code>updateElementGeometry()</code> moves the hit box of an element that is not on the canvas at that place: in the fixture the button was found at 160, 110 where the canvas pixel was 0, 0, 0, 0, and was not found where it had been drawn and wiped.</li>
<li>A <code>drawImage()</code> copy taken inside the paint handler holds the element's picture (0, 160, 0, 255) after the drawable canvas is wiped in the same handler.</li>
<li>A paint event named an element whose text changed although the paint before it left nothing of the element on the canvas.</li>
<li>A tap reached the checkbox of a row moving at 160 px a second with the motor on. A drag that started on a checkbox moved the belt and didn't tick the box.</li>
<li>A row that is mostly round a roller takes no input: the element 26 px down the canvas is the canvas.</li>
<li>One <code>contextlost</code> event stops the canvas and shows the ten rows as plain HTML. Tested by dispatching the event.</li>
<li>Not verified: Chrome 159 on Android, the frame rate on a phone, and a screen reader on a feed whose rows are reused.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/conveyor.md">findings/conveyor.md</a> in the repository.</p>
<p>Asked for by the project owner on 2026-11-22: a virtualised endless list as a conveyor belt, where rows appear from the underside round the bottom roller and disappear over the top roller. Measured in headless Chromium 157 (C157) on 2026-11-22 at 412 px wide. The page's four live checks pass there, and <code>node tools/conveyor/check.mjs</code> drives the belt by touch (22 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: can an endless list be drawn as a conveyor belt from a fixed number of real elements that still take taps while they move?</p>
<p>How it is built: ten <code>drawable</code> row elements. Row i is shown by element i mod 10, refilled when its old row is past the crest of a roller. An element is drawn with <code>drawElementImage()</code> only when its picture changed, copied to a slot of a plain 2D canvas (the atlas) with <code>drawImage()</code>, and wiped. Each frame is cut from the atlas: one piece per row on the flat face, pieces 3 px of belt long round a roller, each shorter by the sine of its angle, narrower by its depth and darker. <code>updateElementGeometry()</code> gives each row its hit box.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Children of the canvas at row 1,000,000 and at row -5</td><td>10 and 10</td><td>The list is computed from the row number and has no end in either direction.</td></tr>
<tr><td>A touch tap on the checkbox of row 4, on Open of row 5, on the checkbox of row 1,000,002</td><td>each reached its element</td><td>The hit box is set with <code>updateElementGeometry()</code>; no element is drawn at the place it appears.</td></tr>
<tr><td>Row 4's tick after its element showed other rows</td><td>kept</td><td>State is stored by row number and written into the element by <code>fill()</code>.</td></tr>
<tr><td>A touch drag of 190 px, held before release</td><td>the belt moved 170 to 200 px; 53 frames, 6 element pictures copied</td><td>Only rows that came onto the belt were drawn as elements.</td></tr>
<tr><td>A flick of 220 px in 80 ms</td><td>about 740 px of travel in all (733 and 744 in two runs), about 166 frames, 18 pictures copied; the belt stopped by itself</td><td></td></tr>
<tr><td>A drag that starts on a checkbox</td><td>moves the belt, does not tick the box</td><td>The click after a drag of more than 6 px is dropped in a capturing listener.</td></tr>
<tr><td>A tap on a checkbox of a row moving at 160 px a second</td><td>ticked</td><td></td></tr>
<tr><td>The element 26 px down the canvas, on the top roller</td><td>the canvas</td><td>A row with less than 45% of its height showing is parked.</td></tr>
<tr><td>ArrowDown with a button of a row focused</td><td>the belt moved to the next row boundary</td><td></td></tr>
<tr><td><code>updateElementGeometry()</code> for an element drawn at 0, 0 and wiped (fixture)</td><td>found at the new place (160, 110), canvas pixel there 0, 0, 0, 0; not found at the old place</td><td>Live check.</td></tr>
<tr><td><code>drawImage()</code> of the drawable canvas into a plain canvas inside the paint handler, then a wipe</td><td>copy 0, 160, 0, 255; drawable canvas 0, 0, 0, 0</td><td>Live check.</td></tr>
<tr><td>A paint event after a text change of an element the last paint left nothing of</td><td>1 event naming 1 element</td><td>Live check. This is how the belt knows which slot to copy again.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event shows the ten rows as plain HTML. Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Going to row 1,000,000 by easing the whole distance refilled all ten elements on every frame (about 1,200 element draws for one jump). The belt now starts twelve rows short of the target and runs the rest.</li>
<li>A slow test drag still ended as a flick, because the last move was under 80 ms before the release. A real finger that stops before lifting does not flick.</li>
<li>The lazy loader imports a module named after the section id. The section was first called <code>belt</code>, which loaded <code>belt.js</code> (no default export) and started nothing.</li>
<li>Row numbers of seven digits were cut off in a 54 px column. The column is 72 px with a 12 px font.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: drag, flick and taps with a real finger, and the frame rate. The canvas has <code>touch-action: none</code>, so a drag that starts on the belt does not scroll the page.</li>
<li>The cost on a phone of about 60 <code>drawImage()</code> slices a frame while the belt moves.</li>
<li>A screen reader: the canvas has <code>role="feed"</code> and rows have <code>aria-posinset</code>, but the rows are reused and their order in the document is not their order on the belt.</li>
<li>Whether a focused control should stay focused when its row leaves the belt. It is blurred when its element is refilled.</li></ul>
<h3>Open ideas</h3>
<ul><li>The same belt in WebGL through <code>ElementGL</code>, with a true cylinder and lighting, behind this 2D route.</li>
<li>A horizontal belt, and a belt whose rows are of different heights.</li>
<li>A sensor line on the belt that reads each row as it passes.</li></ul>
<p><a href="https://html-in-canvas.page/conveyor/">Open Conveyor belt list: an endless list from ten elements, drawn round two rollers</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>DOM pinball made from live form controls</title>
<link>https://html-in-canvas.page/dom-pinball/</link>
<guid isPermaLink="true">https://html-in-canvas.page/dom-pinball/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>physics</category>
<category>forms</category>
<category>range</category>
<category>details</category>
<category>checkbox</category>
<category>hit testing</category>
<description>A 2D physics pinball table built from live HTML controls inside one drawable canvas. Bumpers are buttons that flash on impact, ramps are rotated range sliders you can tilt mid-flight, the diverter gate is a checkbox, the bonus trap is a &lt;details&gt; element, and the flippers are live buttons.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a 2D physics pinball table use real HTML form controls as its bumpers, tiltable ramps, gates, scoreboards and ball traps so collisions mutate the DOM and user taps on the controls change the physics mid-flight?</p>
<p><strong>Short answer:</strong> Not verified in Chromium yet. Six isolated live checks test bumper DOM mutations raising paint, rotated range slider hit boxes, checkbox gate toggles, script-opened details height changes, pivoted flipper clicks and context survival on your device.</p>
<p>
After building the four element games on <a href="https://html-in-canvas.page/play/">/play/</a>, I wanted to push live controls inside a 2D physics loop.
Older DOM physics toys like Google Gravity and Matter.js DOM experiments sync CSS transforms onto elements and fight stacking order when adding trails or shadows.
Here every bumper, tiltable ramp, diverter gate, bonus trap, scoreboard and flipper is a real HTML control inside one drawable canvas, so ball impacts mutate the DOM and your taps alter the physics mid-flight.
</p>
<h3>How it works</h3>
<p>
Every obstacle on the playfield is a real child element of <code>&lt;canvas id="pinball-canvas" content="drawable" layoutsubtree&gt;</code>.
One 2D canvas paints the table background, rail shadows, velocity trails, shockwave rings and the ten controls in a single pass.
On each frame, the paint handler resets the transform, scales to the backing store via a <code>device-pixel-content-box</code> <code>ResizeObserver</code>, and calls five-argument <code>drawElementImage(el, x, y, el.offsetWidth, el.offsetHeight)</code> so high-DPI phones draw every element at its exact CSS size.
</p>
<p>
The two ramps are <code>&lt;input type="range"&gt;</code> controls drawn inside <code>ctx.translate()</code> and <code>ctx.rotate()</code>.
Because <code>drawElementImage()</code> transforms the hit box along with the pixels, dragging either slider thumb changes its value and rotates both the drawn ramp and the physics segment in real time.
Whenever a ramp angle or flipper angle changes, the script toggles a <code>data-moved</code> attribute on that control to clear Chromium's cached hit-test region.
</p>
<p>
Collisions write back to the DOM.
A bumper hit increments its counter, toggles a <code>.hit</code> CSS class and updates the <code>&lt;output&gt;</code> scoreboard.
Rolling into the saucer sets <code>open = true</code> on the <code>&lt;details&gt;</code> element, expanding its laid-out height to reveal <code>+250</code> before ejecting the ball.
Unticking the gate checkbox retracts the right-lane diverter bar so balls drop straight through the express lane.
Because those mutations change the elements' paint records, they raise real <code>paint</code> events even while the physics loop is paused.
</p>
<p>
The animation loop runs only while the table is in view (tracked with <code>IntersectionObserver</code>) and starts paused if <code>prefers-reduced-motion: reduce</code> is set, so you can launch on tap.
If the canvas fires <code>contextlost</code> (or the API isn't available), the page moves the controls into a plain HTML container beside the hidden canvas, and puts them back if <code>contextrestored</code> fires.
</p>
<h3>Findings</h3>
<p>
Not verified in Chromium or on an Android phone yet.
I built this experiment on 2026-11-22 following the hit-testing work on <a href="https://html-in-canvas.page/play/">/play/</a> and older DOM-physics toys (Google Gravity, Matter.js DOM wrappers) to see how far one drawable 2D canvas can carry live form controls inside a moving game.
</p>
<ul>
<li><b>Single-canvas layering avoids CSS transform and z-index workarounds.</b> Ball trails, bumper shockwaves, drop shadows and rotated form controls share one 2D paint pass, while the controls keep native keyboard focus and form state.</li>
<li><b>Bumper hits and saucer traps are live DOM mutations.</b> Adding <code>.hit</code> to a bumper button or setting <code>details.open = true</code> changes the element's CSS or height and triggers a real <code>paint</code> event. Run check 1 and check 4 above to measure this in your browser.</li>
<li><b>Rotated range sliders and pivoted flippers depend on transformed hit boxes.</b> Check 2 and check 5 verify with <code>elementFromPoint()</code> whether Chromium routes pointer input onto the rotated track and flipper blade after toggling <code>data-moved</code>.</li>
<li><b>Touch separation relies on per-element <code>touch-action</code>.</b> The canvas sets <code>touch-action: pan-y</code> so swiping empty playfield scrolls the page on a phone, while the ramp sliders and flippers set <code>touch-action: none</code>. Not verified on real touch hardware.</li>
<li><b>Not verified:</b> Chromium 157 headless pass rates, Chrome on Android touch dragging on rotated <code>&lt;input type="range"&gt;</code> tracks, frame rate during three-ball multi-ball with shockwaves, screen reader announcements for the live <code>&lt;output&gt;</code> scoreboard, and Web Audio latency on a phone.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/dom-pinball.md">findings/dom-pinball.md</a> in the repository.</p>
<p>Built on 2026-11-22. Live browser behaviour is not verified in Chromium 157 (C157) or Chrome on Android (A159) yet; static checks (<code>check:gfx</code> and <code>check:writing</code>) passed locally, and the page ships six isolated live checks to measure each behaviour in the visitor's browser.</p>
<p>This experiment builds on the four element games in <code>/play/</code> and takes inspiration from classic web DOM-physics toys such as Google Gravity and Matter.js DOM wrappers. Rather than syncing CSS transforms onto separate DOM elements and fighting stacking order for shadows and motion trails, every playfield control lives inside one drawable 2D canvas.</p>
<p>The question: can a 2D physics pinball table use real HTML form controls as its bumpers, tiltable ramps, gates, scoreboards and ball traps so collisions mutate the DOM and user taps on the controls change the physics mid-flight?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Three round <code>&lt;button class="bumper" drawable&gt;</code> bumpers mutated by ball impact</td><td>not verified</td><td>On collision, the physics loop adds <code>.hit</code>, increments the bumper's <code>&lt;small&gt;</code> hit counter and updates <code>&lt;output id="scoreboard"&gt;</code>. Live check 1 measures whether the class and text mutation raises <code>paint</code> and changes the copied pixels without calling <code>requestPaint()</code>.</td></tr>
<tr><td>Two <code>&lt;input type="range" drawable&gt;</code> ramp sliders rotated via <code>ctx.rotate()</code></td><td>not verified</td><td>Dragging either slider updates its tilt angle in degrees, redraws the slider rotated with five-argument <code>drawElementImage()</code>, toggles <code>data-moved</code> to clear Chromium's hit-test cache, and rotates the ramp collision segment. Live check 2 tests <code>elementFromPoint()</code> on and off a 25 degree rotated slider.</td></tr>
<tr><td><code>&lt;label drawable&gt;&lt;input type="checkbox"&gt; Gate&lt;/label&gt;</code> diverter barrier</td><td>not verified</td><td>Unticking the checkbox disables the right-lane diverter segment and opens an express <code>+75</code> lane. Live check 3 verifies that changing <code>.checked</code> raises <code>paint</code> and tests the collision solver in both states.</td></tr>
<tr><td><code>&lt;details drawable&gt;</code> saucer trap toggled open on capture</td><td>not verified</td><td>Rolling into the saucer zone sets <code>details.open = true</code>, expanding the drawn control to reveal <code>+250</code> while holding the ball for 720 ms before ejecting it. Live check 4 checks that <code>details.open = true</code> raises <code>paint</code>, increases <code>offsetHeight</code> and paints the revealed bonus pixels.</td></tr>
<tr><td>Two pivoted <code>&lt;button drawable&gt;</code> flippers driven by touch, clicks or keyboard</td><td>not verified</td><td>Each flipper rotates round its hinge using <code>ctx.translate()</code> and <code>ctx.rotate()</code>, transfers surface velocity from angular speed to the ball, and toggles <code>data-moved</code> while swinging. Live check 5 verifies <code>elementFromPoint()</code> and click dispatch on a blade rotated to -25 degrees.</td></tr>
<tr><td>Single 2D canvas budget, reduced motion and <code>contextlost</code> / <code>contextrestored</code> fallback</td><td>not verified</td><td>Logical table is 380 by 560 CSS pixels (~1.47 MP at DPR 2.625, under the 4 MP limit). Loop pauses off screen (<code>IntersectionObserver</code>) and starts paused when <code>prefers-reduced-motion: reduce</code> is set. <code>contextlost</code> moves the ten controls into a plain HTML container; <code>contextrestored</code> moves them back. Live check 6 runs <code>stillDrawn()</code> via a plain <code>drawImage()</code> copy.</td></tr></tbody></table>
<h3>Design notes</h3>
<ul><li>Passing five arguments to <code>drawElementImage(el, x, y, el.offsetWidth, el.offsetHeight)</code> inside the DPR-scaled context keeps every control at its CSS size on high-density phones instead of inflating by <code>devicePixelRatio</code>.</li>
<li>Pixel reads in the live checks and <code>stillDrawn()</code> copy the drawable canvas into a plain 2D canvas (<code>willReadFrequently: true</code>) with <code>drawImage()</code> and retire every fixture canvas with <code>window.__gfx?.retire()</code>.</li>
<li><code>touch-action: pan-y</code> on the canvas and <code>touch-action: none</code> on the ramp sliders and flippers is meant to let you scroll the page from empty playfield space while dragging a ramp or holding a flipper.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in headless Chromium 157 (<code>npm run check:jank -- /dom-pinball/</code> and <code>node tools/draw-size/audit.mjs /dom-pinball/</code>).</li>
<li>Chrome on Android (412 px wide, DPR 2.625): dragging a rotated <code>&lt;input type="range"&gt;</code> thumb with a finger while balls are moving, holding both flippers at once with multitouch, and verifying <code>touch-action</code> separation between the canvas and the sliders.</li>
<li>Frame rate during three-ball multi-ball with trails, drop shadows and expanding bumper rings on a phone GPU.</li>
<li>Screen reader announcements for <code>&lt;output id="scoreboard" aria-live="polite"&gt;</code> and keyboard focus visibility on rotated controls.</li>
<li>Real <code>contextlost</code> and <code>contextrestored</code> recovery on Android hardware, plus Web Audio click and chime latency when the sound checkbox is ticked.</li></ul>
<p><a href="https://html-in-canvas.page/dom-pinball/">Open DOM pinball made from live form controls</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Fields and headings: datalist, password, selectedcontent, title and hgroup</title>
<link>https://html-in-canvas.page/field-heads/</link>
<guid isPermaLink="true">https://html-in-canvas.page/field-heads/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>datalist</category>
<category>input type=password</category>
<category>selectedcontent</category>
<category>title</category>
<category>hgroup</category>
<category>Range</category>
<category>drawElementImage</category>
<description>The suggestions of a &lt;datalist&gt; drawn as chips on a ring round the field, a password field whose picture is only dots, the chosen option of a select drawn large from its &lt;selectedcontent&gt;, the page's own &lt;title&gt; element drawn as a heading, and a subtitle typed out under its heading.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/field-heads/"><img src="https://html-in-canvas.page/field-heads/social.jpg" width="1200" height="630" alt="The page &quot;Fields and headings: datalist, password, selectedcontent, title and hgroup&quot;"></a></p>
<p><strong>Question:</strong> What can a canvas take from a form field or a heading beyond its picture: the options of a datalist, the type of a password field, the box of a selectedcontent, the page's title element, the characters of a subtitle?</p>
<p><strong>Short answer:</strong> All five work in Chromium 157. input.list gives the options and the datalist has no box. A password field's picture is dots, the same for two values of one length. A selectedcontent has a box that a clipped draw enlarges. A title element in a canvas is drawn and still names the tab. A Range gives one rectangle per character.</p>
<p>
The last five ideas of this group from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>. Three are about what a form control gives the
canvas beside its picture: a list of suggestions, a field that hides its value, a copy of a chosen option. Two are about headings: the
document's <code>&lt;title&gt;</code> drawn on the page, and a subtitle typed out under its heading.
</p>
<h3>How it works</h3>
<ul>
<li><b>Data beside the picture.</b> <code>input.list.options</code>, <code>input.type</code>, <code>document.title</code> and the rectangles of a <code>Range</code> are read by script and decide what the canvas draws. None of them needs a readback of pixels.</li>
<li><b>Pieces.</b> The large copy of the chosen option, the blurred field and the growing subtitle are draws of a whole element clipped to a box inside it.</li>
<li><b>Canvas-drawn parts.</b> The chips of the ring aren't elements. A <code>click</code> whose target is the canvas is tested against their shapes.</li>
<li><b>Frames.</b> Each demo asks for frames only while something moves.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-22. Not yet run on a phone.</p>
<ul>
<li><code>input.list.options</code> gives a canvas the suggestions of a <code>&lt;datalist&gt;</code> as data. The datalist is 0 by 0 px and has no picture. With the <code>list</code> attribute removed, <code>input.list</code> is null and the browser opens no list of its own. The eight chips are canvas drawing: typing "ta" left 1 of 8 near the field, and a touch tap on the canvas where a chip is drawn set the field's value.</li>
<li>The picture of a <code>type="password"</code> field holds dots. Two fields with different values of 13 characters gave the same pixels (247 dark pixels each), and a field of 12 characters gave 228, so the picture gives away the length and nothing else. The same value in a text field gave different pixels. The copy in the dark frame blurs the field only while its type isn't <code>password</code>.</li>
<li><code>&lt;selectedcontent&gt;</code> held <code>&lt;b&gt;Red&lt;/b&gt; buoy</code> in a box of 72 by 20 px and followed <code>select.value</code>. In the demo its box is 101 by 32 px for Starboard and 81 by 32 px for Danger, and a draw of the select clipped to that box is shown 3.4 times as large. A touch tap on the drawn select opened its picker and a tap on an option chose it.</li>
<li>A <code>&lt;title&gt;</code> moved into a canvas with <code>display: block</code> has a box (340 by 150 px here), is in the picture, and still names the tab: after typing, <code>document.title</code> and the drawn heading both read "Tide table for Oban".</li>
<li>A <code>Range</code> over each character of the subtitle gave a rectangle for 61 of 61 characters, on 3 lines at 412 px. The subtitle is revealed by clips built from those rectangles, measured once with the group drawn flat.</li>
<li>One <code>contextlost</code> event stops the five canvases and shows the elements as plain HTML. The field gets its <code>list</code> attribute back. Tested by dispatching the event.</li>
<li>Not verified: Chrome 159 on Android, the on-screen keyboard over the ring, a password manager's fill in the drawn field, and the picker of a customisable select on a phone.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/field-heads.md">findings/field-heads.md</a> in the repository.</p>
<p>Backlog group 28 in PLAN.md, ideas 28.1, 28.2, 28.3, 28.15 and 28.18. These are the last five of group 28. Measured in headless Chromium 157 (C157) on 2026-11-22 at 412 px wide. The page's five live checks pass there, and <code>node tools/field-heads/check.mjs</code> drives the five demos by touch (27 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: what can a canvas take from a form field or a heading beyond its picture?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>input.list.options</code> for a drawable field whose <code>&lt;datalist&gt;</code> is inside the canvas</td><td>Oban, Mallaig, Portree; the datalist is 0 by 0 px</td><td>Datalist as a ring of chips (28.1) reads eight options, removes the <code>list</code> attribute and draws the chips itself.</td></tr>
<tr><td><code>input.list</code> after <code>removeAttribute('list')</code></td><td>null</td><td>The browser then opens no list of its own over the canvas. The attribute is put back when the canvas stops drawing.</td></tr>
<tr><td>Typing "ta" in the drawn field; a touch tap on the canvas where the first chip is drawn</td><td>1 of 8 chips match; the field's value became Oban</td><td>The chips are not elements. The tap is a <code>click</code> whose target is the canvas, compared with the chip shapes.</td></tr>
<tr><td>Dark pixels in the picture of two password fields with different values of 13 characters, one of 12, and a text field</td><td>247 and 247, identical pixels; 228; the text field differs</td><td>Password field in a shared view (28.2): the picture of a password field gives away its length only.</td></tr>
<tr><td>The same field after <code>type = 'text'</code></td><td>the picture holds the characters</td><td>The demo's second copy of the form draws that field through <code>blur(7px)</code> with a red frame while its type is not <code>password</code>.</td></tr>
<tr><td><code>&lt;selectedcontent&gt;</code> in a base-select <code>&lt;select&gt;</code> drawn in a canvas</td><td>holds <code>&lt;b&gt;Red&lt;/b&gt; buoy</code> in a box of 72 by 20 px; after <code>select.value = "b"</code> it holds <code>&lt;i&gt;Green&lt;/i&gt; buoy</code></td><td>Hero picture from selectedcontent (28.3) draws the select clipped to that box, 3.4 times as large (box 101 by 32 px for Starboard, 81 by 32 for Danger).</td></tr>
<tr><td>A touch tap on the drawn select, then on an option</td><td>the picker opened (<code>:open</code>), the value changed to danger</td><td>The picker is in the top layer, over the canvas.</td></tr>
<tr><td>A <code>&lt;title&gt;</code> with <code>display: block</code> inside a canvas</td><td>200 by 29 px, <code>HTMLTitleElement</code>, 84 of 200 pixels in a row across it drawn</td><td>Title element as a heading (28.15) moves the page's own title into the canvas (340 by 150 px there).</td></tr>
<tr><td><code>document.title</code> with the title element inside the canvas, after typing</td><td>"Tide table for Oban", and the drawn heading reads the same</td><td>It is still the first title element in the document.</td></tr>
<tr><td>A <code>Range</code> over each character of a paragraph in an <code>&lt;hgroup&gt;</code></td><td>34 of 34 characters have a rectangle, on 2 lines; 61 of 61 on 3 lines in the demo</td><td>Subtitle typed under its heading (28.18): the paragraph is revealed by clips made from those rectangles, 38 ms a character.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the five canvases and shows the elements as plain HTML (5 boxes), and <code>input.list</code> is the datalist again. Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first shadow under the title heading was a skewed second draw. It crossed the heading's own lines and made them hard to read. It is now a blurred draw offset by 5 and 8 px.</li>
<li><code>selectedcontent.textContent</code> includes the option's <code>&lt;small&gt;</code> note, which the page's style sheet hides in the button, so the text in the line under the demo is longer than what the box shows.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the five demos by touch.</li>
<li>The on-screen keyboard over the ring: whether the chips stay in view while typing.</li>
<li>A password manager or autofill in the drawn password field, and whether a real screen share shows the same pixels as the canvas copy.</li>
<li>The picker of a customisable select on a phone, which may be a native sheet.</li>
<li>What the tab strip and the task switcher show for a title element that is inside a canvas.</li></ul>
<p><a href="https://html-in-canvas.page/field-heads/">Open Fields and headings: datalist, password, selectedcontent, title and hgroup</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Linear-light colour spaces, contrast-color() and ctx.lang</title>
<link>https://html-in-canvas.page/linear-color/</link>
<guid isPermaLink="true">https://html-in-canvas.page/linear-color/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>srgb-linear</category>
<category>display-p3-linear</category>
<category>contrast-color()</category>
<category>ctx.lang</category>
<category>CSS.registerProperty()</category>
<description>Three colour and text APIs paired with drawElementImage(): side-by-side srgb and srgb-linear (or display-p3-linear) canvases blending neon badges, a card using CSS contrast-color() over a reactive canvas tint, and ctx.lang next to drawn CJK DOM text.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Do linear-light canvas colour spaces, CSS contrast-color() and CanvasTextDrawingStyles.lang work with drawElementImage()?</p>
<p><strong>Short answer:</strong> Side-by-side srgb and linear-light canvases compare blurred and overlapping neon controls, a registered --tint property drives contrast-color() on a drawn card, and ctx.lang sits next to a drawn span with CJK Han variants. Open the live checks below to see what your browser supports.</p>
<p>
I wanted to test three newer colour and text APIs alongside <code>drawElementImage()</code>:
linear-light 2D canvas colour spaces (<code>srgb-linear</code> and <code>display-p3-linear</code>),
CSS <code>contrast-color()</code> driven by a canvas tint, and <code>CanvasTextDrawingStyles.lang</code>
next to drawn CJK DOM text. Drag the sliders, click the neon badges and switch the language to see what your browser supports.
</p>
<h3>How it works</h3>
<p>
In an <code>srgb</code> canvas, alpha compositing and <code>ctx.filter = 'blur(...)'</code> average gamma-encoded channel values.
Half red plus half cyan ends up at sRGB 0.5, which is only about 21% physical light, so the overlap looks dark and muddy.
When the canvas uses <code>srgb-linear</code> or <code>display-p3-linear</code>, the same 50% mix averages linear light and encodes to about 0.73 sRGB, so blurred glows and overlapping neon controls stay bright.
Switching between <code>srgb-linear</code> and <code>display-p3-linear</code> replaces the right canvas and calls <code>window.__gfx?.retire()</code> on the old one because a canvas can't change its context attributes after creation.
</p>
<p>
For the contrast demo, <code>CSS.registerProperty()</code> defines <code>--tint</code> with <code>syntax: '&lt;color&gt;'</code>.
The sliders update <code>--tint</code> on the drawable card and request a paint. The canvas paints a gradient backdrop from that colour and draws the card on top, while CSS <code>contrast-color(var(--tint))</code> picks black or white text based on relative luminance (yellow at 50% lightness flips to black while blue at 50% lightness stays white).
</p>
<p>
In the third demo, <code>ctx.lang</code> tells Canvas 2D which regional font variant to pick when shaping Han characters that share a Unicode code point across Japanese, Simplified Chinese and Traditional Chinese (<code>直 骨 海 角 刃 令</code>).
The canvas copies the computed font size and family from the <code>&lt;span&gt;</code>, draws with <code>ctx.fillText()</code>, and calls <code>drawElementImage()</code> on the <code>&lt;span lang="..."&gt;</code> element right beside it so you can compare strokes directly.
</p>
<h3>Findings</h3>
<ul>
<li>Not verified yet in headless Chromium or on Android Chrome 159. The live checks above measure your browser directly when this page opens.</li>
<li>To verify linear-light blending: check that <code>getContext('2d', { colorSpace: 'srgb-linear' })</code> and <code>'display-p3-linear'</code> report those strings in <code>getContextAttributes().colorSpace</code>, and that overlapping red and cyan <code>drawElementImage()</code> calls measure brighter in <code>srgb-linear</code> than in <code>srgb</code> (around 188 vs 128 in sRGB 8-bit).</li>
<li>To verify <code>contrast-color()</code>: check that <code>CSS.supports('color', 'contrast-color(red)')</code> is true and that dragging the lightness slider or tapping Yellow (50%) vs Blue (50%) flips the drawn card's text between black and white.</li>
<li>To verify <code>ctx.lang</code>: check that <code>'lang' in CanvasRenderingContext2D.prototype</code> is true and compare the glyph strokes of <code>直 骨 海 角 刃 令</code> between <code>ctx.fillText()</code> and <code>drawElementImage()</code> on a system that has distinct Japanese, Simplified Chinese and Traditional Chinese fonts installed.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/linear-color.md">findings/linear-color.md</a> in the repository.</p>
<p>Not verified in headless Chromium (C157) or on the test phone (A159) as of 2026-11-22. The page was written and checked with <code>npm run check:gfx</code> and <code>node tools/writing/check.mjs</code>; the live checks on the page report exact browser support and pixel measurements when opened.</p>
<p>The page pairs three newer colour and text APIs with 2D <code>drawElementImage()</code>: side-by-side <code>srgb</code> and <code>srgb-linear</code> (with a toggle for <code>display-p3-linear</code>) canvases blending neon DOM buttons, a drawable card whose text uses CSS <code>contrast-color(var(--tint))</code> over a reactive canvas tint, and <code>CanvasTextDrawingStyles.lang</code> beside a drawn <code>&lt;span lang="..."&gt;</code> displaying CJK Han variant characters (<code>直 骨 海 角 刃 令</code>).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>getContext('2d', { colorSpace: 'srgb-linear' })</code> accepted on a drawable canvas</td><td>not verified</td><td>Check 1 inspects <code>ctx.getContextAttributes().colorSpace</code>.</td></tr>
<tr><td><code>getContext('2d', { colorSpace: 'display-p3-linear' })</code> accepted on a drawable canvas</td><td>not verified</td><td>Check 2 inspects <code>ctx.getContextAttributes().colorSpace</code>.</td></tr>
<tr><td>Overlapping red and cyan <code>drawElementImage()</code> calls blend brighter in <code>srgb-linear</code> than in <code>srgb</code></td><td>not verified</td><td>Check 3 draws <code>#ff0000</code> under 50% <code>#00ffff</code>, copies both canvases into plain <code>willReadFrequently</code> 2D canvases and compares the centre RGB values (expected ~188 vs ~128 in sRGB 8-bit).</td></tr>
<tr><td><code>ctx.filter = 'blur(8px)'</code> over a red/cyan <code>drawElementImage()</code> seam blends brighter in <code>srgb-linear</code></td><td>not verified</td><td>Check 4 compares the midpoint pixel across the blurred seam.</td></tr>
<tr><td><code>CSS.supports('color', 'contrast-color(red)')</code> and black/white flip on <code>var(--tint)</code></td><td>not verified</td><td>Check 5 tests dark blue vs bright yellow with a registered <code>--tint</code> (<code>syntax: '&lt;color&gt;'</code>).</td></tr>
<tr><td>Changing <code>--tint</code> updates the drawn pixels of a <code>drawable</code> card using <code>contrast-color(var(--tint))</code></td><td>not verified</td><td>Check 6 draws a fixture card before and after flipping <code>--tint</code> and counts changed pixels from a plain copy.</td></tr>
<tr><td><code>CanvasTextDrawingStyles.lang</code> accepts <code>'ja'</code>, <code>'zh-Hans'</code> and <code>'zh-Hant'</code></td><td>not verified</td><td>Check 7 checks <code>'lang' in CanvasRenderingContext2D.prototype</code> and reads back each tag.</td></tr>
<tr><td><code>ctx.lang</code> and <code>drawElementImage(&lt;span lang&gt;)</code> render matching CJK Han variants</td><td>not verified</td><td>Check 8 draws <code>直骨海角刃令</code> with <code>ja</code> and <code>zh-Hans</code> on both paths and reports pixel differences; systems with one shared CJK fallback font will show 0 px difference.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A 2D canvas cannot switch <code>colorSpace</code> after <code>getContext()</code> has been called. Toggling between <code>srgb-linear</code> and <code>display-p3-linear</code> therefore creates a fresh <code>&lt;canvas content="drawable" layoutsubtree&gt;</code>, moves the four neon <code>&lt;button&gt;</code> children into it with <code>moveBefore()</code> (falling back to <code>append()</code>), removes the old canvas and calls <code>window.__gfx?.retire(old)</code>.</li>
<li>Reading pixels directly from a drawable canvas or setting <code>willReadFrequently: true</code> on a drawable canvas loses 2D canvases on Android Chrome 159. All pixel checks copy the drawable canvas into a plain 2D canvas with <code>drawImage()</code> and read from the copy.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157: run <code>npm run check:jank -- /linear-color/</code> and record the live check results, layout shift count and memory estimate.</li>
<li>Android Chrome 159 at 412 px wide (device pixel ratio 2.625): confirm touch dragging on the sliders, button hit testing in both canvases after toggling <code>srgb-linear</code> and <code>display-p3-linear</code>, and no context loss.</li>
<li>Display P3 hardware screen: confirm visual gamut difference when switching the right canvas from <code>srgb-linear</code> to <code>display-p3-linear</code> with <code>color(display-p3 ...)</code> neon buttons.</li>
<li>A device with separate Japanese, Simplified Chinese and Traditional Chinese CJK fonts installed: confirm that <code>ctx.fillText()</code> with <code>ctx.lang</code> picks the same regional glyph variants as <code>drawElementImage()</code> on <code>&lt;span lang&gt;</code>.</li></ul>
<p><a href="https://html-in-canvas.page/linear-color/">Open Linear-light colour spaces, contrast-color() and ctx.lang</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Liquid glass toolbar over scrolling DOM</title>
<link>https://html-in-canvas.page/liquid-glass/</link>
<guid isPermaLink="true">https://html-in-canvas.page/liquid-glass/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>texElementSubImage2D</category>
<category>WebGL</category>
<category>refraction</category>
<category>SDF</category>
<category>scroll</category>
<category>touch</category>
<description>A floating HTML navigation pill drawn over a live scrolling article in one WebGL 2 canvas. A fragment shader refracts the scrolling page through a rounded-rectangle lens with Snell's-law bending, chromatic dispersion, frosted blur and a pointer-lit Fresnel rim, while both the toolbar and the page behind it stay clickable and selectable.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a floating HTML navigation pill refract the live scrolling DOM behind it using Snell's-law lensing and chromatic dispersion in WebGL, while both the refracted toolbar and the scrolling page beneath it stay clickable and selectable?</p>
<p><strong>Short answer:</strong> Not verified yet in a live browser. One ElementGL canvas uploads both the scrolling article and the floating pill via texElementSubImage2D(), refracts the article texture through a rounded-rectangle SDF lens with chromatic dispersion and a 9-tap frost kernel, composites the pill DOM on top, and updates hit boxes with updateElementGeometry().</p>
<p>
I wanted to know if a floating HTML navigation pill can refract a live scrolling article behind it using Snell's-law lensing and chromatic dispersion in WebGL, while both the toolbar and the page underneath stay clickable and selectable. Scroll the article, drag the pill across the high-contrast cards, and try the buttons on both layers.
</p>
<h3>How it works</h3>
<p>
This experiment takes inspiration from Apple's Liquid Glass material design (WWDC 2025) and community WebGL and
WebGPU refractive glass UI demos. CSS <code>backdrop-filter: blur()</code> can frost pixels behind a floating bar,
but it can't bend them around a curved bevel or split red, green and blue like a physical lens. HTML-in-canvas gives
a fragment shader the live rendered pixels of the DOM behind the bar as a GPU texture, so the shader can run Snell's
law on every frame while the markup stays interactive.
</p>
<p>
Both <code>#lg-page</code> (the scrollable article) and <code>#lg-dock</code> (the floating navigation pill) live
inside one <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> managed by <code>ElementGL</code> from
<code>/lib/element-gl.js</code>. Inside the <code>paint</code> handler, each element is uploaded with
<code>gl.texElementSubImage2D()</code> when it changes or when the article scrolls. Pass 0 draws the article across
the full canvas. Pass 1 draws a quad at the pill's current rectangle, binds the article texture to
<code>TEXTURE1</code> and the pill's own DOM texture to <code>TEXTURE0</code>, evaluates a rounded-rectangle signed
distance field for the curved glass bevel, refracts three slightly different indices of refraction for red, green
and blue, adds a 9-tap frosted micro-blur and pointer-lit Fresnel highlight, and composites the crisp toolbar pixels
over the glass body.
</p>
<p>
Because the pill is drawn at its dragged coordinates rather than at its CSS layout origin, the paint handler calls
<code>canvas.updateElementGeometry()</code> for both children (scaled by <code>geometryUnit()</code> from
<code>/lib/surface.js</code> for high-DPI screens) and toggles <code>dataset.hitTick</code> whenever the pill moves
to clear Chromium's hit-test cache. When WebGL <code>texElementSubImage2D()</code> isn't available, the page falls
back to a 2D frosted draw with <code>drawElementImage()</code> or unwraps the markup as plain HTML with
<code>backdrop-filter: blur()</code>.
</p>
<h3>Findings</h3>
<ul>
<li>Apple's Liquid Glass material design (WWDC 2025) and community WebGL and WebGPU refractive glass UI demos inspired this layout. With CSS <code>backdrop-filter: blur()</code> alone, a floating toolbar can blur what sits behind it, yet it can't curve the background along a bevel or separate RGB channels through a lens.</li>
<li>Putting both the scrolling container and the floating toolbar in one <code>ElementGL</code> canvas avoids opening a second WebGL context and lets the glass pass sample the scrolling article directly on texture unit 1.</li>
<li>Listening to <code>scroll</code> on <code>#lg-page</code> and calling <code>requestPaint()</code> with a dirty flag makes sure the article texture re-uploads while you scroll, even if a browser build doesn't list a scroll-only update in <code>changedElements</code>.</li>
<li>Keeping <code>#lg-dock</code>'s own CSS background transparent lets the fragment shader render the refracted lens, Fresnel rim and pointer glint behind the toolbar's live text and buttons, then composite the premultiplied DOM texture over the glass.</li>
<li>Setting <code>touch-action: none</code> on the floating pill and <code>touch-action: pan-y</code> on the article lets you drag the pill on a touch screen without scrolling the outer page, while dragging outside the pill scrolls the article normally.</li>
<li>Not verified: live rendering, scroll smoothness, touch dragging and frame rate in Chromium 157 (headless) and Chrome 159 on Android. Open the page in a browser with HTML-in-canvas enabled and tap Run on the live checks above to verify on your device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/liquid-glass.md">findings/liquid-glass.md</a> in the repository.</p>
<p>Not verified in a live browser yet (written 2026-11-22). All live checks wait for a tap (<code>&lt;meta name="checks" content="tap"&gt;</code>) and run on isolated fixtures in the visitor's browser.</p>
<p>This experiment takes inspiration from Apple's Liquid Glass material design (WWDC 2025) and community WebGL and WebGPU refractive glass UI demos. CSS <code>backdrop-filter: blur()</code> can frost pixels behind a floating bar, yet it can't bend them through a curved bevel or split RGB channels like a physical lens. Here, one <code>ElementGL</code> canvas (<code>/lib/element-gl.js</code>) holds both <code>#lg-page</code> (a live scrollable article with selectable text, contrast cards, checkboxes and a newsletter form) and <code>#lg-dock</code> (a floating navigation pill). Pass 0 draws the article; Pass 1 samples the article texture on <code>TEXTURE1</code> through a rounded-rectangle SDF lens with Snell's-law refraction, chromatic dispersion, a 9-tap frosted micro-blur and a pointer-lit Fresnel rim, then composites the live <code>#lg-dock</code> DOM texture on top.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>One <code>ElementGL</code> canvas uploading both <code>#lg-page</code> and <code>#lg-dock</code> via <code>texElementSubImage2D()</code></td><td>not verified</td><td>Checked by live check 1 on a 220 by 120 fixture (<code>preserveDrawingBuffer: true</code> + <code>readPixels()</code>).</td></tr>
<tr><td>Snell's-law UV bending near the rounded pill bevel</td><td>not verified</td><td>Checked by live check 2 across a red-to-blue vertical seam with <code>uRefraction = 0</code> vs <code>1.5</code>.</td></tr>
<tr><td>Chromatic dispersion across a black-and-white vertical edge</td><td>not verified</td><td>Checked by live check 3 by measuring peak <code>|R - B|</code> along the bevel seam on a greyscale background.</td></tr>
<tr><td>Re-uploading <code>#lg-page</code> while it scrolls</td><td>not verified</td><td>Checked by live check 4 (<code>scrollTop = 0</code> red block vs <code>scrollTop = 80</code> green block); the demo also listens to <code>scroll</code> and flags <code>pageDirty = true</code> before calling <code>requestPaint()</code>.</td></tr>
<tr><td><code>updateElementGeometry()</code> + <code>dataset.hitTick</code> syncing hit boxes for a dragged pill over a scrolling article</td><td>not verified</td><td>Checked by live checks 5 and 6 via <code>elementFromPoint()</code> and click handlers on both layers.</td></tr>
<tr><td>Visual legibility and drag smoothness at 412 px wide on touch</td><td>not verified</td><td>Needs a live run on Chrome 159 on Android and headless Chromium 157.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>ElementGL.quad()</code> binds the drawn element's own texture to <code>TEXTURE0</code> (<code>uTex</code>). To sample the background article inside the floating pill pass without opening a second WebGL context, Pass 0 stores the <code>{ tex, w, h }</code> handle returned by <code>stage.upload(pageEl)</code> and Pass 1 binds <code>pageTex.tex</code> to <code>TEXTURE1</code> (<code>uBgTex</code>) inside <code>quad()</code>'s uniform callback.</li>
<li><code>updateElementGeometry()</code> has been seen to take CSS pixels on some canvases and backing-buffer pixels on others at high device pixel ratios. The paint handler scales both matrices with <code>geometryUnit()</code> from <code>/lib/surface.js</code> and toggles <code>dataset.hitTick</code> when a layer moves or resizes so Chromium clears its hit-test cache.</li>
<li>Dragging a floating pill that contains real <code>&lt;button&gt;</code> elements needs a movement threshold (6 px when "Drag anywhere on pill" is checked) and a capture-phase click suppressor after a drag, otherwise dragging either steals taps or fires accidental clicks on release.</li></ul>
<h3>Not verified</h3>
<ul><li>Chromium 157 (headless): running all 6 live checks, verifying <code>npm run check:jank -- /liquid-glass/</code> and <code>node tools/draw-size/audit.mjs /liquid-glass/</code>, and capturing <code>social.jpg</code>.</li>
<li>Chrome 159 on Android (412 px wide, device pixel ratio 2.625): touch dragging <code>#lg-dock</code> with <code>touch-action: none</code> over <code>#lg-page</code> (<code>touch-action: pan-y</code>), text selection under and around the pill, keyboard entry in the newsletter <code>&lt;input&gt;</code>, real frame rate during scrolling, and behaviour after a context loss.</li>
<li>Chromium 153: fallback behaviour when WebGL <code>texElementSubImage2D()</code> is missing or behaves differently.</li></ul>
<h3>Open ideas</h3>
<ul><li>Add a WebGPU route via <code>/shared/backend.js</code> alongside the <code>ElementGL</code> WebGL 2 route so visitors can compare GPU cost and shader behaviour on both backends.</li>
<li>Drive the pill's refraction and bevel uniforms from registered CSS custom properties (<code>@property</code>) so CSS transitions animate the glass when the toolbar docks or floats.</li></ul>
<p><a href="https://html-in-canvas.page/liquid-glass/">Open Liquid glass toolbar over scrolling DOM</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Eurorack modular synth with dangling patch cables</title>
<link>https://html-in-canvas.page/modular-synth/</link>
<guid isPermaLink="true">https://html-in-canvas.page/modular-synth/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawable descendants</category>
<category>drawElementImage</category>
<category>form controls</category>
<category>Web Audio</category>
<category>AnalyserNode</category>
<category>Verlet physics</category>
<description>Three drawable &lt;fieldset&gt; synth modules (VCO, LFO and VCF/Mix) sit inside one 2D canvas. Verlet-simulated patch cables dangle in front of the HTML controls with cast shadows and a live phosphor oscilloscope while every slider, select and jack stays clickable and keyboard-accessible.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a single 2D canvas draw real HTML form controls as Eurorack synth modules with physical Verlet-simulated patch cables hanging in front of them, cast shadows and live oscilloscope traces while every slider, selector and jack stays keyboard- and touch-accessible?</p>
<p><strong>Short answer:</strong> Built and statically checked; live browser rendering, touch patching and audio output are not verified yet. The page runs six live checks on isolated fixtures in the visitor's browser.</p>
<p>
I wanted to know if one 2D canvas could draw three HTML form panels as Eurorack synthesiser modules, drape physical
Verlet-simulated patch cables in front of them with cast shadows and a live oscilloscope, and still leave every slider,
select and jack clickable and keyboard-accessible. Drag from one 3.5 mm jack to another (or tap two jacks in turn) to
rewire the patch, and press Power inside the VCF module to start Web Audio.
</p>
<h3>How it works</h3>
<p>
The idea comes from hardware Eurorack modular synthesisers, VCV Rack's dangling patch cables, and two earlier experiments on this site:
<a href="https://html-in-canvas.page/instruments/">form controls drawn as instruments</a> and the <a href="https://html-in-canvas.page/cassette/">cassette deck from audio controls</a>, which
established that standard HTML form controls can be drawn inside a canvas as tactile audio hardware while keeping keyboard and touch input.
</p>
<ul>
<li>One 2D canvas with <code>content="drawable" layoutsubtree</code> holds three <code>&lt;fieldset drawable&gt;</code> modules: VCO-1, LFO-1 and VCF/Mix. A <code>ResizeObserver</code> sizes the canvas backing store in device pixels and fits the modules into either one row (desktop) or two compact rows (narrow phones around 412 px).</li>
<li>Each frame paints the brushed-aluminium rails and M3 mounting screws first, then calls five-argument <code>drawElementImage(mod, x, y, w, h)</code> for each module. That call both copies the module's live pixels and places its hit-test region at <code>(x, y, w, h)</code>.</li>
<li>Next, the canvas draws the glowing phosphor oscilloscope waveform straight over the VCF module's recessed <code>.scope-slot</code> box, plus a pulsing LFO rate LED beside the LFO header.</li>
<li>Last, the canvas paints the cast drop shadows, braided jackets and 3.5 mm plugs of every active Verlet patch cable over the top of the drawn modules. Canvas strokes have no DOM hit box of their own, so clicks, drags and focus pass straight through a hanging cable to the sliders and selects behind it.</li>
<li>Audio stays off on load. Clicking Power inside the VCF module creates and resumes an <code>AudioContext</code>, wires the oscillator, LFO and biquad filter according to the active cables, and feeds the oscilloscope from an <code>AnalyserNode</code>. If the canvas loses its context or the API is missing, the three <code>&lt;fieldset&gt;</code> modules move into a plain CSS grid with every control still working.</li>
</ul>
<h3>Findings</h3>
<p>Built 2026-11-22. Live browser rendering, Android touch patching and Web Audio output are not verified yet; run the checks above in Chrome with HTML-in-canvas enabled to measure your browser.</p>
<ul>
<li><strong>Prior work credited:</strong> this layout builds on hardware Eurorack synthesisers, VCV Rack's dangling patch cables, and <a href="https://html-in-canvas.page/instruments/">/instruments/</a> plus <a href="https://html-in-canvas.page/cassette/">/cassette/</a> on this site.</li>
<li><strong>Design: cables in front, hit boxes underneath.</strong> Because 2D canvas paths painted after <code>drawElementImage()</code> don't alter the element's hit-test transform, dangling cables can cross directly over range sliders and <code>&lt;select&gt;</code> menus without stealing taps. Lower the Cable opacity slider to inspect the overlap.</li>
<li><strong>Design: phone pixel budget.</strong> At 412 CSS px wide and scale 2.625, the two-row skiff is 590 CSS px tall (about 1.68 megapixels, well under the 4-megapixel guard limit).</li>
<li><strong>Not verified:</strong> live rendering in Chromium 157 headless and Chrome 159 on Android, touch drag patching vs. page scroll on Android, native <code>&lt;select&gt;</code> popup anchoring inside a drawn <code>&lt;fieldset&gt;</code>, and real-time Web Audio output with <code>AnalyserNode</code>.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/modular-synth.md">findings/modular-synth.md</a> in the repository.</p>
<p>Built on 2026-11-22. Static graphics and writing checks passed; live browser checks in Chromium 157 headless (C157) and Chrome 159 on Android (A159) are not verified yet.</p>
<p>Prior work credited: hardware Eurorack modular synthesisers, VCV Rack's dangling patch cables, and <code>/instruments/</code> plus <code>/cassette/</code> on this site (which showed that real HTML form controls can be drawn inside a canvas as tactile audio hardware).</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Three drawable <code>&lt;fieldset&gt;</code> synth modules (<code>VCO-1</code>, <code>LFO-1</code>, <code>VCF / MIX</code>) drawn in one 2D canvas with five-argument <code>drawElementImage()</code></td><td>not verified</td><td>Check 1 paints three isolated <code>&lt;fieldset drawable&gt;</code> modules on <code>testStage()</code> and verifies pixel coverage via a plain 2D copy canvas.</td></tr>
<tr><td>Verlet-simulated patch cables with cast shadows painted after <code>drawElementImage()</code></td><td>not verified</td><td>Check 2 verifies orange cable strokes composite over blue module pixels via a plain 2D copy canvas.</td></tr>
<tr><td>Form controls (<code>&lt;input type="range"&gt;</code>, <code>&lt;select&gt;</code>, <code>&lt;button&gt;</code>) hit-tested behind painted cables</td><td>not verified</td><td>Check 3 paints opaque cables directly over a range slider and button and asserts <code>document.elementFromPoint()</code> still returns the HTML controls.</td></tr>
<tr><td>Slider mutation inside a drawn <code>&lt;fieldset&gt;</code> updates the canvas picture</td><td>not verified</td><td>Check 4 changes a fixture range input from 10 to 95 and counts changed pixels via a plain 2D copy.</td></tr>
<tr><td>Jack rewiring and 12-node Verlet rope sag</td><td>not verified (browser)</td><td>Check 5 exercises <code>createPatchEngine()</code> directly: normalising reversed jack order, checking midpoint sag after 20 Verlet steps, and unplugging a cable.</td></tr>
<tr><td>Live canvas survives fixture checks (<code>stillDrawn()</code>)</td><td>not verified</td><td>Check 6 inspects <code>#rack-canvas</code> through a plain <code>drawImage()</code> copy and falls back to plain HTML if blank.</td></tr>
<tr><td>Web Audio patch routing (<code>AudioContext</code>, <code>OscillatorNode</code>, <code>BiquadFilterNode</code>, <code>AnalyserNode</code>)</td><td>not verified</td><td>Starts only on user tap of the Power button inside <code>VCF / MIX</code>. Muted preview math drives the oscilloscope on initial load.</td></tr>
<tr><td>Responsive two-row phone skiff (412 px wide at 2.625 scale)</td><td>not verified</td><td>Backing store caps below 4 megapixels (<code>590 CSS px</code> tall on mobile, about 1.68 megapixels at 2.625 DPR).</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Keeping hit-testing accurate across both desktop (one row) and narrow mobile (two rows) meant sizing each <code>&lt;fieldset class="rack-mod"&gt;</code> to the exact CSS width and height of its slot before calling five-argument <code>drawElementImage(mod, s.x, s.y, s.w, s.h)</code>.</li>
<li>Reading jack coordinates and the oscilloscope window via <code>offsetLeft</code> and <code>offsetTop</code> relative to each <code>&lt;fieldset&gt;</code> avoids mixing scroll-dependent viewport coordinates into canvas-space cable endpoints.</li>
<li>Touch drag on a 3.5 mm jack button needs <code>touch-action: none</code> on <code>.jack</code> so dragging a patch cable doesn't pan the page, while keeping <code>touch-action: pan-y</code> on the canvas so normal vertical scrolling still works outside the jacks.</li>
<li>All pixel readbacks in the live checks copy through a plain temporary <code>&lt;canvas&gt;</code> (<code>willReadFrequently: true</code>) and call <code>window.__gfx?.retire(copy)</code> instead of reading directly from a drawable canvas, following the Chrome 159 Android context-loss findings in <code>docs/graphics-rules.md</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in Chromium 157 headless (<code>C157</code>) and running <code>npm run check:jank -- /modular-synth/</code> (run both after <code>npm run build</code> in a browser-enabled pass).</li>
<li>Touch drag patching and two-tap patching on Chrome 159 on Android (<code>A159</code>) at 412 px wide, including whether dragging a jack conflicts with page scrolling.</li>
<li>Native <code>&lt;select&gt;</code> dropdown popup anchoring when opened from inside a drawn <code>&lt;fieldset&gt;</code> on desktop and Android.</li>
<li>Real-time Web Audio output, filter cutoff CV modulation and <code>AnalyserNode</code> oscilloscope frames after pressing Power on real hardware.</li>
<li><code>contextlost</code> and <code>contextrestored</code> fallback switching on Android under GPU memory pressure.</li></ul>
<p><a href="https://html-in-canvas.page/modular-synth/">Open Eurorack modular synth with dangling patch cables</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Visual node graph made of live HTML forms</title>
<link>https://html-in-canvas.page/node-graph/</link>
<guid isPermaLink="true">https://html-in-canvas.page/node-graph/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>node graph</category>
<category>bezier</category>
<category>forms</category>
<category>zoom</category>
<description>Four draggable HTML form nodes connected by glowing Bézier wires on one pan-and-zoom 2D canvas. Drag headers to move nodes, drag or tap ports to rewire the live signal graph, and zoom from 35% to 300% while text and inputs re-rasterise sharply.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can an infinite pan-and-zoom node graph draw glowing Bézier wires behind draggable HTML <code>&lt;form&gt;</code> nodes on one 2D canvas so text stays sharp from 35% overview to 300% zoom without CSS-transform blur?</p>
<p><strong>Short answer:</strong> Not verified in Chromium yet; live checks below measure 2.5x zoom drawing, hit-testing on moved and zoomed inputs, wire occlusion, live rewiring and context survival in your browser.</p>
<p>
Tools like Blender Shader Nodes, ComfyUI, cables.gl, Rete and React Flow pair graph wires with parameter cards, but zooming DOM nodes with CSS <code>transform</code> blurs text once you pass 150%, while drawing form controls by hand on a canvas throws away browser inputs. After <a href="https://html-in-canvas.page/board/">/board/</a> showed that 2D <code>drawElementImage()</code> re-rasterises DOM vector paint commands sharply at any scale, I built a four-node signal graph of real <code>&lt;form&gt;</code> elements with glowing Bézier wires drawn behind them on one 2D canvas. Drag the background to pan, drag node headers to rearrange, drag or tap ports to rewire, and zoom from 35% to 300%.
</p>
<h3>How it works</h3>
<p>
Node-based editors such as Blender Shader Nodes, ComfyUI, cables.gl, Rete and React Flow all face the same browser split: put HTML controls on top of an SVG wire layer and CSS <code>transform: scale()</code> rasterises cards into a bitmap that turns fuzzy at 250% zoom, or draw the whole graph onto a canvas and rebuild every slider, dropdown and text input from scratch. Following <a href="https://html-in-canvas.page/board/">/board/</a>, this experiment puts four <code>&lt;form drawable&gt;</code> elements directly inside one <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> and lets one 2D paint handler draw both the wires and the DOM.
</p>
<p>
On each <code>paint</code> event, the 2D context scales by <code>devicePixelRatio</code>, draws the background dot grid, and strokes every active wire as a horizontal-tangent cubic Bézier curve (an outer glow pass plus a bright core coloured by the live signal). Each visible form node then draws on top under <code>ctx.translate(sx, sy); ctx.scale(cam.k, cam.k);</code> with 5-argument <code>ctx.drawElementImage(node.el, 0, 0, w, h)</code>. Because <code>drawElementImage()</code> replays the element's paint commands under the current canvas matrix, labels, borders, inputs and the inline preview SVG re-rasterise cleanly from 35% overview to 300% close-up, and hit-testing tracks the same matrix.
</p>
<p>
Nodes dragged off screen aren't drawn, so the paint handler calls <code>canvas.updateElementGeometry(node.el, { canvasTransform: OFFSTAGE })</code> to park their hit boxes away from clicks. After a node drag or camera move finishes, the script toggles a <code>data-hit</code> attribute on moved forms so Chromium clears its hit-test cache without triggering a paint loop. When HTML-in-canvas isn't available or the 2D context fires <code>contextlost</code>, the four forms move into a plain CSS grid with a visible notice so every control keeps working.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Prior art and inspiration.</strong> The node-and-wire interaction follows Blender Shader Nodes, ComfyUI, cables.gl, Rete and React Flow, while the zoomable 2D <code>drawElementImage()</code> camera builds directly on <a href="https://html-in-canvas.page/board/">/board/</a>.</li>
<li><strong>Single-canvas layering removes overlay sync.</strong> Drawing glowing cubic Bézier wires first and calling <code>drawElementImage()</code> for each form afterwards puts wires behind nodes in one coordinate space, with zero DOM z-index clashes and no separate SVG transform matrix to keep aligned during pan and zoom.</li>
<li><strong>Port anchors stay exact from CSS layout offsets.</strong> Reading each port button's <code>offsetTop</code> relative to its <code>&lt;form&gt;</code> gives graph-space coordinates that don't depend on current camera zoom or device scale, so wires stay locked to port dots while dragging or zooming.</li>
<li><strong>Off-screen nodes need explicit hit-box parking.</strong> Skipping <code>drawElementImage()</code> for a culled node leaves its previous hit region active until <code>updateElementGeometry()</code> parks it off stage and a DOM attribute toggle clears the hit-test cache.</li>
<li><strong>Verification status.</strong> Live browser runs in headless Chromium 157 and Chrome 159 on Android are not verified yet; the six checks above run on isolated fixtures in your browser and report their own pixel and hit-test measurements directly.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/node-graph.md">findings/node-graph.md</a> in the repository.</p>
<p>Built on 2026-11-22. Inspired by node editors such as Blender Shader Nodes, ComfyUI, cables.gl, Rete and React Flow, and building on <code>/board/</code> (which showed that 2D <code>drawElementImage()</code> re-rasterises DOM vector paint commands sharply at any zoom scale). Source checked with <code>npm run check:gfx</code> and <code>node tools/writing/check.mjs --strict</code>. Live browser execution in headless Chromium 157 (C157) and Chrome 159 on Android (A159) is <strong>not verified</strong> in this run; the six checks on the page run on isolated fixtures in the visitor's browser and report their own pixel and hit-test measurements directly.</p>
<p>The question: can an infinite pan-and-zoom node graph draw glowing Bézier wires behind draggable HTML <code>&lt;form&gt;</code> nodes on one 2D canvas so text stays sharp from 35% overview to 300% zoom without CSS-transform blur?</p>
<table><thead><tr><th>Experiment</th><th>Status</th><th>Notes</th></tr></thead><tbody><tr><td>Drawing a <code>&lt;form drawable&gt;</code> node at 2.5x zoom via <code>drawElementImage()</code></td><td>Not verified</td><td>Live check 1 scales an isolated form node to 2.5x, copies the canvas into a plain 2D canvas via <code>drawImage()</code>, and checks luminance contrast and sharp pixel step transitions across the scaled text and border.</td></tr>
<tr><td>Hit-testing a moved and zoomed form control</td><td>Not verified</td><td>Live check 2 translates an isolated <code>&lt;form drawable&gt;</code> to <code>(45, 24)</code> at 1.8x zoom, toggles <code>data-hit</code> to clear Chromium's hit-test cache, and checks <code>document.elementFromPoint()</code> over its button.</td></tr>
<tr><td>Layering glowing cubic Bézier wires behind form nodes on one 2D canvas</td><td>Not verified</td><td>Live check 3 strokes a red cubic Bézier wire across the canvas before calling <code>drawElementImage()</code> for an opaque white card, then verifies wire pixels stay visible outside the node while the node centre stays solid white.</td></tr>
<tr><td>Live rewiring of output and input ports updating the computed graph output</td><td>Not verified</td><td>Live check 4 runs <code>evaluateGraph()</code> and <code>buildPreviewSvg()</code> on a routed 4-wire chain vs a bypassed 1-wire chain (<code>gen:signal -&gt; out:signal</code>) and confirms <code>transformed</code>, <code>paletteActive</code> and the SVG output update deterministically.</td></tr>
<tr><td>Parking an off-screen node with <code>updateElementGeometry()</code></td><td>Not verified</td><td>Live check 5 draws a node button, confirms hit-testing hits it, skips <code>drawElementImage()</code> on the next paint while parking it off stage with <code>updateElementGeometry()</code>, and checks that the old coordinates no longer hit the button.</td></tr>
<tr><td>Context loss fallback and visible canvas survival (<code>stillDrawn()</code>)</td><td>Not verified</td><td>The page listens for <code>contextlost</code> and <code>contextrestored</code>, moving the four <code>&lt;form&gt;</code> nodes into a plain CSS grid with a visible notice on loss. Live check 6 runs <code>stillDrawn()</code> on a plain <code>drawImage()</code> copy of <code>#graph-canvas</code>.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Measuring port anchor coordinates with <code>getBoundingClientRect()</code> depends on the canvas's current zoom and DPR, which drifts during drags. Walking <code>offsetTop</code> from each <code>.port-btn</code> up to its <code>&lt;form&gt;</code> gives exact graph-space coordinates that stay locked to the port dots at any zoom level.</li>
<li>Toggling a DOM attribute on a drawable form inside <code>paint</code> can trigger another <code>paint</code> event. Clearing Chromium's hit-test cache (<code>node.el.dataset.hit = ...</code>) only when a node drag, pan or zoom settles avoids a paint loop while keeping form inputs clickable in their new positions.</li>
<li>Putting a second <code>&lt;canvas&gt;</code> inside <code>#node-out</code> for the live pattern swatch would add a second context and more backing-store memory. Rendering the procedural Sine, Spiral, Checker and Plasma swatch as an inline <code>&lt;svg&gt;</code> keeps the page to one 2D canvas and lets the swatch vectors re-rasterise cleanly at 300% zoom alongside the form labels.</li>
<li>Starting continuous <code>requestAnimationFrame</code> pulse animation on load burns battery and risks jank checks on low-end phones. Signal pulses start off, pause automatically when the stage leaves the viewport or the tab hides, and stay off when <code>prefers-reduced-motion: reduce</code> is active.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /node-graph/</code> and <code>node tools/draw-size/audit.mjs /node-graph/</code>): run both to verify zero layout shift, backing-store sizing at 412 px wide and scale 2.625, zero timed readbacks, and all six live check results.</li>
<li>Chrome 159 on Android at 412 px wide by touch: 1-finger background panning, 2-finger pinch zoom from 35% to 300%, dragging node headers, tap-to-wire and drag-to-wire on port buttons, interacting with native <code>&lt;select&gt;</code>, <code>&lt;input type="range"&gt;</code> and <code>&lt;input type="color"&gt;</code> controls at 250% zoom, and minimap tap-panning.</li>
<li>Visual sharpness comparison at 250% to 300% zoom on a HiDPI screen against a CSS <code>transform: scale(2.5)</code> baseline.</li></ul>
<p><a href="https://html-in-canvas.page/node-graph/">Open Visual node graph made of live HTML forms</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Old and odd elements: font, marquee, xmp, blink, a foreign iframe and a footer</title>
<link>https://html-in-canvas.page/odd-elements/</link>
<guid isPermaLink="true">https://html-in-canvas.page/odd-elements/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>marquee</category>
<category>font</category>
<category>xmp</category>
<category>HTMLUnknownElement</category>
<category>iframe</category>
<category>footer</category>
<category>updateElementGeometry</category>
<description>A 1990s page of &lt;center&gt;, &lt;font&gt; and &lt;marquee&gt; on the tube of a drawn monitor, an &lt;xmp&gt; whose tags the canvas colours, an audit that outlines unknown elements, a warning over frames the canvas can't draw, and a footer that lies on the ground with links that still work.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/odd-elements/"><img src="https://html-in-canvas.page/odd-elements/social.jpg" width="1200" height="630" alt="The page &quot;Old and odd elements: font, marquee, xmp, blink, a foreign iframe and a footer&quot;"></a></p>
<p><strong>Question:</strong> What does a canvas get from elements at the edges of HTML (font and marquee, xmp, names the parser doesn't know, a frame from another origin, a footer used as a floor), and what does it have to find out another way?</p>
<p><strong>Short answer:</strong> In Chromium 157 old and unknown elements are all in the picture, and a marquee inside a drawable block raised 60 paint events a second. A frame from another origin is left out (alpha 0) and still takes taps; a null contentDocument finds it. An xmp has no child elements, so its tags are coloured from Range rectangles. updateElementGeometry() takes a perspective matrix on a 2D canvas, so links on a slanted footer are hit-tested by the browser.</p>
<p>
Five ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a> about elements at the edges of HTML: the presentational elements of the
1990s, <code>&lt;xmp&gt;</code>, names the parser does not know, a frame from another origin, and a footer used as a floor. Each demo
asks what the element gives a canvas to draw, and what the canvas has to find out some other way.
</p>
<h3>How it works</h3>
<ul>
<li><b>What the picture holds.</b> Old elements, unknown elements and <code>&lt;xmp&gt;</code> are all in the picture of the block around them. A frame from another origin is not.</li>
<li><b>What the canvas adds.</b> The colours behind the tags, the outlines of the audit and the hatching over a frame are drawn by the canvas from rectangles: <code>getClientRects()</code> of an element or of a <code>Range</code>, which are reported at the place where the block was last drawn.</li>
<li><b>Strips.</b> The slant of the floor is many clipped draws of one element, each with its own scale. The bulge of the tube is cut from a <code>drawImage()</code> copy of one flat draw, which costs one picture of the element for a frame and not eleven.</li>
<li><b>Frames.</b> A demo asks for frames only while something moves. The monitor is redrawn by the marquee's own paint events.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-22. Not yet run on a phone.</p>
<ul>
<li><b>A frame from another origin is a hole in the picture that still takes taps.</b> A pixel inside a <code>data:</code> frame and inside a sandboxed <code>srcdoc</code> frame had alpha 0 in the canvas. A frame from this origin had its own red there. <code>elementFromPoint()</code> gave the frame in all three, and in the demo one tap on each empty box pressed the button inside.</li>
<li><b>The canvas can find such a frame without reading pixels.</b> <code>contentDocument</code> was null for the two foreign frames and a document for the third. The warning is drawn from that and from the frame's rectangle.</li>
<li><b>The elements of the 1990s still draw.</b> <code>center</code>, <code>big</code>, <code>tt</code>, <code>nobr</code> and <code>acronym</code> are plain <code>HTMLElement</code>, <code>font</code> is <code>HTMLFontElement</code> and <code>marquee</code> is <code>HTMLMarqueeElement</code>. All had boxes and all are in the picture.</li>
<li><b>A marquee inside a drawable block is a clock for the canvas.</b> It raised 120 paint events in two seconds, and <code>changedElements</code> named the drawable block in all of them. The first version drew the block ten times on each event, one of them blurred, and the software-rendered test browser spent 10.4 s of a six-second run in long tasks. The page now draws the block once, 12 times a second, copies those pixels with <code>drawImage()</code> and builds the tube from the copy: 2.8 s in the same run.</li>
<li><b>Unknown names draw too.</b> <code>blink</code>, <code>applet</code> and <code>spacer</code> are <code>HTMLUnknownElement</code> and were 36, 47 and 52 px wide with their text. A name with a hyphen that was never defined is an <code>HTMLElement</code>, told apart by <code>customElements.get()</code>.</li>
<li><b>An xmp is text all the way down.</b> Its <code>textContent</code> was the markup, it had 0 child elements, and it accepted <code>contenteditable="plaintext-only"</code>. A <code>Range</code> over one tag gave a rectangle of 25 by 16 px, which is all the canvas needs to colour it.</li>
<li><b><code>updateElementGeometry()</code> takes a perspective matrix on a 2D canvas.</b> A button was found at the place the matrix projects it to, and the place where it was drawn flat gave the canvas. The footer's picture needs 3 px strips, and its hit region needs one call.</li>
<li><b>Not verified:</b> everything on a phone. The cost of redrawing the tube at the marquee's rate, typing into the xmp with an on-screen keyboard, and a frame from a real second site, which may be in another process (the two foreign frames here are a <code>data:</code> URL and a sandbox).</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/odd-elements.md">findings/odd-elements.md</a> in the repository.</p>
<p>Backlog group 28 in PLAN.md, ideas 28.17, 28.21, 28.23, 28.24 and 28.28. Measured in headless Chromium 157 (C157) on 2026-11-22 at 412 px wide. The page's five live checks pass there, and <code>node tools/odd-elements/check.mjs</code> drives the five demos by touch (25 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: what does a canvas get from elements at the edges of HTML, and what does it have to find out another way?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Three frames of 90 by 50 px with solid backgrounds in one drawable block: <code>srcdoc</code>, a <code>data:</code> URL, a sandboxed <code>srcdoc</code>. One pixel inside each, read from a <code>drawImage()</code> copy</td><td>this origin: 255, 0, 0, alpha 255. <code>data:</code> frame: alpha 0. Sandboxed frame: alpha 0</td><td>A frame whose origin differs is left out of the picture. An opaque origin counts.</td></tr>
<tr><td><code>elementFromPoint()</code> inside each of the three</td><td>the frame, 3 of 3</td><td>The empty box still takes input. In the demo one touch tap on each pressed the button inside (a <code>postMessage</code> from the frame).</td></tr>
<tr><td><code>contentDocument</code> of each</td><td>a document, null, null</td><td>How Warn about invisible frames (28.21) finds them with no readback. It hatches the rectangle and counts the taps the frame took.</td></tr>
<tr><td>Interfaces and widths in a drawable block</td><td>blink, applet, spacer: <code>HTMLUnknownElement</code>, 36, 47, 52 px. my-badge, center, big, tt, nobr, acronym: <code>HTMLElement</code>. font: <code>HTMLFontElement</code>. xmp: <code>HTMLPreElement</code>. marquee: <code>HTMLMarqueeElement</code></td><td>Unknown elements in a design system audit (28.23) outlines 3 unknown, 2 undefined custom and 4 obsolete elements in its paragraph as a line passes down it.</td></tr>
<tr><td>A marquee (<code>scrollamount="5"</code>, default delay) inside a drawable block</td><td>120 paint events in two seconds; <code>changedElements</code> named the block in 120</td><td>Old web page in a drawn monitor (28.28) uses those events as its only clock. It draws the block once, copies the pixels with <code>drawImage()</code>, and cuts the copy into 11 strips with a bulge, a <code>lighter</code> copy for the glow, lines and a shadow, 12 times a second.</td></tr>
<tr><td>A tap on the button of the page on the tube; the same place with the power off</td><td>the count on the page went from 000042 to 000043; with the power off the element there is the canvas</td><td>The page is placed flat on the screen with a clipped-away draw, and parked with the power off.</td></tr>
<tr><td>An <code>xmp</code> with <code>contenteditable="plaintext-only"</code></td><td><code>textContent</code> is the markup, 0 child elements, editable; a <code>Range</code> over <code>&lt;b&gt;</code> gives 1 rectangle, 25 by 16 px</td><td>xmp as a literal code sample (28.24): 12 tags coloured by the canvas under the element's picture, and the same text parsed into a second element.</td></tr>
<tr><td>Typing <code>&lt;u&gt;new&lt;/u&gt;</code> and then an <code>img</code> with <code>onerror</code> and a <code>script</code> into the xmp</td><td>14 tags, the copy gained a <code>u</code>; neither script ran</td><td>The text is parsed in a <code>DOMParser</code> document, and script-like elements, <code>on*</code> attributes and <code>javascript:</code> links are removed before it is moved into the page.</td></tr>
<tr><td><code>updateElementGeometry()</code> with a matrix that has a perspective row, on a 2D canvas</td><td>a button was found at its projected place (150, 132); the place it was drawn flat gave the canvas</td><td>Footer that is the floor (28.17): links on the footer answered at 46 and at 20 degrees of tilt, and the button of a sign standing on it.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the five canvases and shows the elements as plain HTML (5 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>setHTML()</code> removed the <code>button</code> from the typed markup, so the copy had 5 elements where the text has 6. The page parses with <code>DOMParser</code> and removes what can run.</li>
<li>Ten draws of the old page on each of 60 paint events a second, one with <code>blur(3px)</code>, gave 10.4 s of long tasks in a six-second run of <code>check:jank</code> (software rendering, scale 2.625). Without the blur it was 3.2 s. <code>scrolldelay="200" truespeed</code> did not lower the rate of paint events. The demo now draws the block once per frame at 12 frames a second and builds the tube from a <code>drawImage()</code> copy: 2.8 s.</li>
<li>The page first said the marquee steps about 12 times a second, from its default delay of 85 ms. The check counted 60 paint events a second.</li>
<li>The floor's strips showed dark seams with a clip 0.6 px deeper than the strip. The clip is now 2 px deeper.</li>
<li>At 58 degrees the far half of the footer was unreadable at 412 px. The slider starts at 46 and stops at 66.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the five demos by touch.</li>
<li>A frame from a second real site. Such a frame can be in another process. The two foreign frames here are in this process with an opaque origin.</li>
<li>The cost of the monitor on a phone. The long tasks left in the test browser (2.8 s in six) have not been traced further.</li>
<li>Typing into the <code>xmp</code> with an on-screen keyboard, and whether <code>plaintext-only</code> keeps one text node there.</li>
<li>A screen reader on the slanted footer.</li></ul>
<p><a href="https://html-in-canvas.page/odd-elements/">Open Old and odd elements: font, marquee, xmp, blink, a foreign iframe and a footer</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Origami boarding pass and tear-off stub</title>
<link>https://html-in-canvas.page/origami-ticket/</link>
<guid isPermaLink="true">https://html-in-canvas.page/origami-ticket/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>captureElementImage</category>
<category>clip</category>
<category>origami</category>
<category>hit testing</category>
<description>A live HTML boarding pass drawn on one 2D canvas as two sibling drawable sections. Fold it into four sheared origami panels, or drag across the dotted perforation to tear off the stub along a jagged edge while both halves stay clickable and editable.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a single live HTML boarding pass fold along scored origami creases and rip cleanly along a serrated perforation into two separate interactive pieces on a 2D canvas?</p>
<p><strong>Short answer:</strong> Not verified in a live browser yet. The page draws two sibling <code>drawable</code> halves with five-argument and nine-argument <code>drawElementImage()</code>, restores hit regions after sliced draws with an empty-clip full draw, and runs six isolated checks in your browser.</p>
<p>
I wanted to know if one live HTML boarding pass can fold into concertina panels and rip along a serrated perforation into two separate interactive pieces on a 2D canvas.
This builds directly on the sheared-strip folding in <a href="https://html-in-canvas.page/accordion/">/accordion/</a> and the paper peel in <a href="https://html-in-canvas.page/view-source/">/view-source/</a>, paired with the physical tear-off stub pattern from mobile wallet boarding passes.
Edit the passenger name, change the seat, drag the paper body to fold it, or drag the <b>Tear here</b> tab to unzip the stub.
</p>
<h3>How it works</h3>
<p>I split the boarding pass into two sibling <code>drawable</code> children inside one 2D canvas: <code>#pass-main</code> and <code>#pass-stub</code>. While the pass is flat and untorn, each half takes one unclipped five-argument <code>drawElementImage(el, x, y, w, h)</code> call right beside its neighbour. That keeps every input, select menu, checkbox, and button aligned to its painted pixels.</p>
<p>When you fold the pass, I slice the combined width (or height on a narrow phone screen) into four hinged panels using nine-argument <code>drawElementImage(source, sx, sy, sw, sh, dx, dy, dw, dh)</code>, borrowing the alternating shear idea from <a href="https://html-in-canvas.page/accordion/">/accordion/</a>. Cosine foreshortening narrows each panel as the fold angle grows, alternating affine shear builds the mountain and valley ridges, and linear gradients shade the creases.</p>
<p>When you drag the <b>Tear here</b> handle or pull the tear slider, the canvas draws complementary sawtooth clip paths along the perforation seam. Below 75%, the stub pivots away from the remaining uncut hinge like physical ticket paper, inspired by the paper-peel interaction on <a href="https://html-in-canvas.page/view-source/">/view-source/</a> and wallet pass stubs. Once the rip passes 75%, a damped spring flings <code>#pass-stub</code> clear at a slight angle. At the snap point I take one brief <code>captureElementImage()</code> snapshot of the stub for a faint motion trail and call <code>close()</code> as soon as the spring settles, so zero snapshots stay open at rest.</p>
<p>A nine-argument draw shrinks an element's hit region to that slice. After drawing folded panels or serrated clips, I run an empty-clip five-argument <code>drawElementImage()</code> for each half under its current transform (matching the hit-restore pattern in <code>/lib/text-canvas.js</code>) and toggle a <code>data-hit</code> attribute when motion stops so Chromium clears its hit-test cache. Because <code>#pass-main</code> and <code>#pass-stub</code> are separate <code>drawable</code> children, both halves stay interactive after the tear.</p>
<h3>Findings</h3>
<ul>
<li>Direct inspirations: <a href="https://html-in-canvas.page/accordion/">/accordion/</a> for sheared-strip folding on a 2D canvas, <a href="https://html-in-canvas.page/view-source/">/view-source/</a> for tactile paper peeling, and physical tear-off boarding pass stubs from mobile wallet UIs.</li>
<li>Putting <code>#pass-main</code> and <code>#pass-stub</code> as two sibling <code>drawable</code> children avoids the single-element hit-box tradeoff: if the whole ticket were one <code>drawable</code> node, tearing it apart into two positions would leave only one half with a live hit box. With two siblings, the detached rotated stub can receive clicks on <b>Scan stub</b> and <b>Priority boarding</b> while <code>#pass-main</code> keeps working separately.</li>
<li>At rest (<code>fold &lt;= 0.01</code> and untorn), drawing each half with one unclipped five-argument <code>drawElementImage()</code> avoids any hit-box shrink from nine-argument slices.</li>
<li>This page hasn't been run in a live browser yet, so every runtime behaviour below is <b>not verified</b> until the checks run in Chromium 157 and on Chrome 159 for Android (412 px touch, device pixel ratio 2.625).</li>
<li>Not verified: real-device frame rate during the 4-panel shear and spring fling, hit accuracy on the rotated detached stub in Chrome 159 on Android, native <code>&lt;select&gt;</code> popup alignment when folded or torn, and TalkBack / VoiceOver focus order across the two halves.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/origami-ticket.md">findings/origami-ticket.md</a> in the repository.</p>
<p>Not verified in a live browser as of 2026-11-22. Built and checked statically (<code>npm run check:gfx</code> and <code>tools/writing/check.mjs --strict</code>), waiting for a run in C157 and on A159.</p>
<p>Direct inspirations: <code>/accordion/</code> (sheared-strip <code>&lt;details&gt;</code> folding on a 2D canvas), <code>/view-source/</code> (paper-peel interaction), and physical boarding-pass tear-off stubs in mobile wallet UIs.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Four sheared nine-argument <code>drawElementImage()</code> strips folding a boarding pass across creases</td><td>not verified</td><td>Drawn with alternating affine shear and cosine foreshortening (<code>drawFoldedPass()</code>). Check 1 tests ink inside the foreshortened half vs the vacated area on a plain <code>drawImage()</code> copy.</td></tr>
<tr><td>Two sibling <code>drawable</code> halves (<code>#pass-main</code> and <code>#pass-stub</code>) keeping independent hit targets after tearing apart</td><td>not verified</td><td>Both halves stay live <code>drawable</code> elements inside one <code>&lt;canvas content="drawable" layoutsubtree&gt;</code>. Check 2 draws <code>#fm</code> and a displaced, rotated <code>#fs</code>, toggles <code>data-hit</code>, and runs <code>elementFromPoint()</code> on buttons in both.</td></tr>
<tr><td>Restoring a full hit box after a nine-argument slice using an empty-clip five-argument draw</td><td>not verified</td><td>Follows the empty-clip pattern from <code>/lib/text-canvas.js</code> (<code>home()</code>). Check 3 draws a 70 px slice of a 220 px element, restores its hit box with an empty clip, and hit-tests a button at <code>x = 175</code>.</td></tr>
<tr><td>Jagged sawtooth polygon clip over nine-argument <code>drawElementImage()</code></td><td>not verified</td><td><code>clipSerrated()</code> clips complementary teeth along the perforation seam. Check 4 samples ink left and right of the teeth via a plain <code>drawImage()</code> copy.</td></tr>
<tr><td>Brief <code>captureElementImage()</code> motion trail closed immediately when the spring settles</td><td>not verified</td><td>The fling animation captures one snapshot of <code>#pass-stub</code>, fades it out, and calls <code>close()</code> as soon as the spring settles (or on rejoin, <code>contextlost</code>, or <code>pagehide</code>). Check 5 verifies drawing before <code>close()</code> and throwing after <code>close()</code>, with cleanup in <code>try/finally</code>.</td></tr>
<tr><td>Unclipped five-argument draws at rest (<code>fold &lt;= 0.01</code>, untorn)</td><td>not verified</td><td>Avoids any hit-box shrink while editing the <code>&lt;input&gt;</code>, changing <code>&lt;select&gt;</code>, ticking the checkbox, or pressing buttons.</td></tr></tbody></table>
<h3>Design tradeoffs</h3>
<ul><li><strong>Two sibling <code>drawable</code> children vs one wrapper.</strong> If the whole boarding pass were one <code>drawable</code> node, tearing the stub away into a second rotated position would leave only whichever draw ran last with a live hit box. Splitting into <code>#pass-main</code> and <code>#pass-stub</code> lets both halves stay clickable and editable at separate transforms after the tear, while drawing side by side with zero gap when untorn.</li>
<li><strong>Perforation touch drag vs form controls.</strong> Putting <code>touch-action: none</code> on the dedicated <code>#seam-handle</code> pill and keeping <code>touch-action: pan-y</code> on <code>#stage-canvas</code> avoids blocking page scroll on a 412 px phone, while ignoring <code>pointerdown</code> events that start on <code>input</code>, <code>select</code>, <code>button</code>, or <code>label</code> leaves native typing and taps alone.</li>
<li><strong>No <code>getImageData()</code> on drawable canvases.</strong> Every pixel check in the live checks copies the fixture canvas into a plain 2D canvas with <code>willReadFrequently: true</code> via <code>drawImage()</code>, reads from the copy, and calls <code>window.__gfx?.retire(copy)</code> before zeroing it.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in C157 (headless Chromium) and confirming all six pass with zero layout shift (<code>npm run check:jank -- /origami-ticket/</code>) and zero draw-size mismatches (<code>node tools/draw-size/audit.mjs /origami-ticket/</code>).</li>
<li>Real-device frame rate and touch feel on A159 (Chrome 159 on Android, 412 px wide, device pixel ratio 2.625), including vertical perforation tearing on narrow screens and hit accuracy on the rotated detached stub.</li>
<li>Native <code>&lt;select&gt;</code> popup placement while folded or torn, and TalkBack / VoiceOver focus order between <code>#pass-main</code> and <code>#pass-stub</code>. Open the page on an Android phone with TalkBack on, fold and tear the ticket, and step through the controls to verify.</li></ul>
<p><a href="https://html-in-canvas.page/origami-ticket/">Open Origami boarding pass and tear-off stub</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Foldable paper OpenStreetMap pocket map</title>
<link>https://html-in-canvas.page/osm-fold/</link>
<guid isPermaLink="true">https://html-in-canvas.page/osm-fold/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>OpenStreetMap</category>
<category>fold</category>
<category>clip</category>
<category>hit testing</category>
<description>Real OpenStreetMap tiles and four live interactive HTML place pins plus a legend card drawn together on one 2D canvas. Fold the map into four vertical concertina panels and across a horizontal midline crease like a paper pocket map, or unfold it flat to click pins, filter stops, and pan the map.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can real OpenStreetMap tiles and live interactive HTML place pins fold together along vertical and horizontal Ordnance-Survey-style accordion creases on a 2D canvas while staying clickable when unfolded?</p>
<p><strong>Short answer:</strong> Not verified in a live browser yet. The page composites live OpenStreetMap tiles with procedural fallback tiles onto an offscreen canvas, slices both the tiles and five sibling <code>drawable</code> HTML cards across a 4x2 hinged paper grid with nine-argument <code>drawElementImage()</code>, and switches to unclipped five-argument draws when flat.</p>
<p>I wanted to see if real OpenStreetMap tiles and live interactive HTML place pins could fold together along vertical and horizontal paper-map creases on one 2D canvas. Drag the edges of the map or use the fold presets to crease it into a pocket map, then unfold it flat to click stops, filter the legend, and pan the streets.</p>
<h3>How it works</h3>
<p>I built this around a single <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> and a plain offscreen 2D canvas that holds the map sheet. The offscreen canvas composites live raster tiles from <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> (<code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code> with <code>crossOrigin = 'anonymous'</code>), cached in memory by <code>z/x/y</code>. While tiles are loading or if the device is offline, each 256 by 256 tile slot draws a deterministic procedural street, river, park, and grid tile in the colour palette of Ordnance Survey pocket paper maps. The dashed walking route, neatline ticks, scale bar, and pin anchor dots draw onto that same offscreen sheet.</p>
<p>The four place pins (<code>#pin-0</code> to <code>#pin-3</code>) and the pocket legend card (<code>#map-legend</code>) sit inside the canvas as sibling <code>drawable</code> HTML elements. When the map is flat (<code>foldX &lt;= 0.01</code> and <code>foldY &lt;= 0.01</code>), I draw the offscreen sheet once and then draw each HTML element with a single unclipped five-argument <code>drawElementImage(el, x, y, w, h)</code>. That leaves every button, search input, and checkbox with an exact native hit box while you pan the map underneath.</p>
<p>Once either fold slider moves off zero, the renderer switches to a 4 by 2 grid of hinged paper panels, extending the sheared-strip folding pattern from <a href="https://html-in-canvas.page/accordion/">/accordion/</a> and <a href="https://html-in-canvas.page/origami-ticket/">/origami-ticket/</a> into two axes. Each of the four vertical columns applies cosine foreshortening and alternating vertical affine shear (<code>ctx.transform(cosX, shearY, 0, scaleY, dx, dy)</code>) so adjacent vertical creases meet without gaps. Inside every panel clip, I copy the matching strip of the offscreen tile atlas and slice every overlapping HTML pin or legend card with nine-argument <code>drawElementImage(el, sx, sy, sw, sh, dx, dy, dw, dh)</code> so tiles, routes, and live DOM bend together along the exact same creases.</p>
<p>The horizontal midline crease folds the top half down over the bottom half. Below 50% vertical fold, the top row foreshortens upward toward the midline. Past 50%, it flips downward over the bottom row and draws the cream paper back with an Ordnance-Survey-style pocket cover. Tight horizontal folding (past 72%) also swings a hinged back-cover pocket flap over the edge of the concertina stack. When elements are hidden under the folded cover, I call <code>park()</code> from <code>/lib/stage-2d.js</code> so covered buttons don't intercept taps; when motion settles back to flat, toggling a <code>data-hit</code> attribute clears Chromium's hit-test cache.</p>
<h3>Findings</h3>
<ul>
<li>Credits and inspirations: map tiles by <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>, physical accordion-and-midline folding from Ordnance Survey and pocket tourist paper maps, and the sheared-strip 2D canvas folding pattern from <a href="https://html-in-canvas.page/accordion/">/accordion/</a> and <a href="https://html-in-canvas.page/origami-ticket/">/origami-ticket/</a> on this site.</li>
<li>Sharing one affine matrix per panel between <code>drawImage(atlasCanvas, ...)</code> and nine-argument <code>drawElementImage(el, ...)</code> keeps map tiles, vector routes, and live HTML cards locked across both vertical and horizontal creases with no visible drift between layers.</li>
<li>Keeping the offscreen OpenStreetMap tile atlas on a plain non-drawable 2D canvas avoids creating extra drawable contexts and keeps pixel compositing fast during drags, while the fallback procedural renderer lets the experiment remain legible offline or when tile servers rate-limit requests.</li>
<li>Switching back to unclipped five-argument <code>drawElementImage()</code> when <code>foldX &lt;= 0.01</code> and <code>foldY &lt;= 0.01</code> avoids the hit-box shrinkage caused by nine-argument slices while typing in <code>#pin-filter</code> or clicking pin route buttons.</li>
<li>This page hasn't been run in a live browser yet, so every runtime behaviour is <b>not verified</b> until the checks run in Chromium 157 and on Chrome 159 for Android (412 px touch, device pixel ratio 2.625).</li>
<li>Not verified: real-device frame rate while folding live OpenStreetMap PNG tiles plus five <code>drawable</code> HTML cards across eight clipped panels on Chrome 159 for Android, CORS delivery of <code>tile.openstreetmap.org</code> tiles under mobile network throttling, touch panning vs margin-drag ergonomics at 412 px wide, and screen-reader focus order when pins are parked under the back cover.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/osm-fold.md">findings/osm-fold.md</a> in the repository.</p>
<p>Not verified in a live browser as of 2026-11-22. Built and checked statically (<code>npm run check:gfx</code> and <code>tools/writing/check.mjs --strict</code>), waiting for a run in C157 and on A159.</p>
<p>Credits and inspirations: map tiles from OpenStreetMap (<code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code>, copyright OpenStreetMap contributors), physical accordion and midline folding from Ordnance Survey and pocket tourist paper maps, and the sheared-strip 2D canvas folding pattern from <code>/origami-ticket/</code> and <code>/accordion/</code> on this site.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Four vertical accordion panels folding a composited OpenStreetMap tile atlas and live HTML place pins together in lockstep</td><td>not verified</td><td><code>drawFoldedMap()</code> applies one affine matrix (<code>cosX</code>, alternating <code>shearY</code>) per column to both <code>drawImage(atlasCanvas, ...)</code> and nine-argument <code>drawElementImage(el, ...)</code> slices. Check 1 tests ink compression on a plain <code>drawImage()</code> copy.</td></tr>
<tr><td>Horizontal midline crease folding the top half down over the bottom half with an Ordnance-Survey-style back cover</td><td>not verified</td><td>Below 50% vertical fold the top row foreshortens upward toward the midline hinge (<code>cosY</code>); past 50% it flips down over the bottom row and renders <code>drawPocketBackCover()</code>. Check 2 tests top-half foreshortening vs the anchored bottom half.</td></tr>
<tr><td>Unfolded five-argument <code>drawElementImage()</code> keeping exact hit boxes on pin buttons and the legend filter input</td><td>not verified</td><td>When <code>foldX &lt;= 0.01</code> and <code>foldY &lt;= 0.01</code>, <code>#pin-0</code> through <code>#pin-3</code> and <code>#map-legend</code> each draw once with unclipped five-argument <code>drawElementImage()</code>. Check 3 verifies <code>elementFromPoint()</code> on a fixture pin button and legend input.</td></tr>
<tr><td>Restoring a full hit box after nine-argument panel slicing with an empty-clip five-argument draw</td><td>not verified</td><td><code>restoreHit()</code> runs when lightly folded (<code>foldX &lt;= 0.55</code> and <code>foldY &lt;= 0.5</code>), while <code>park()</code> moves controls out of hit testing when hidden behind the folded cover. Check 4 tests hit restoration on a sliced fixture.</td></tr>
<tr><td><code>captureElementImage()</code> pin snapshot lifecycle (draw before <code>close()</code>, throw after <code>close()</code>)</td><td>not verified</td><td>Check 5 captures a pin fixture snapshot, confirms ink on a plain <code>drawImage()</code> copy, closes it in <code>try/finally</code>, and checks that a second draw throws.</td></tr>
<tr><td>Context loss and blank canvas resilience on <code>#map-canvas</code></td><td>not verified</td><td><code>mount()</code> from <code>/lib/stage-2d.js</code> falls back to plain HTML via <code>toPlain()</code> on <code>contextlost</code>, <code>onLost</code> retires the offscreen <code>atlasCanvas</code>, and Check 6 (<code>stillDrawn()</code>) verifies <code>#map-canvas</code> keeps drawn pixels after all fixture checks retire.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><strong>Keeping vertical creases joined across a horizontal midline hinge.</strong> For the top half to lean forward or fold down without splitting apart between adjacent accordion columns, every column's <code>f</code> translation term has to anchor on the sheared midline (<code>hingeY + ridgeY - cosY * halfH</code> before 50%, <code>hingeY + ridgeY</code> after 50%) while keeping <code>c = 0</code> and sharing the same <code>cosX</code> and <code>shearY</code>. That keeps adjacent columns joined to the sub-pixel along all three vertical creases at every combination of <code>foldX</code> and <code>foldY</code>.</li>
<li><strong>Panning vs folding on one canvas.</strong> Starting a drag on a live <code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, or <code>&lt;label&gt;</code> exits <code>pointerdown</code> immediately so taps and typing reach the DOM controls. On an unfolded map, dragging inside the interior pans the OpenStreetMap tiles while dragging within the outer margin (34 px on narrow screens, 44 px on desktop) folds the paper; once any fold is active, dragging anywhere on the canvas adjusts both fold axes.</li>
<li><strong>No <code>getImageData()</code> on drawable canvases.</strong> Every pixel check copies the fixture canvas into a plain non-drawable 2D canvas with <code>willReadFrequently: true</code>, reads from the copy, calls <code>window.__gfx?.retire(copy)</code>, and zeroes <code>copy.width</code> and <code>copy.height</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in C157 (headless Chromium) and confirming zero layout shift (<code>npm run check:jank -- /osm-fold/</code>) and zero draw-size mismatches (<code>node tools/draw-size/audit.mjs /osm-fold/</code>).</li>
<li>Live network loading of <code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code> with <code>crossOrigin = 'anonymous'</code> across London, Edinburgh, and Kyoto, plus tile server rate-limit behaviour and offline procedural fallback switchover.</li>
<li>Real-device frame rate and touch ergonomics on A159 (Chrome 159 on Android, 412 px wide, device pixel ratio 2.625) while dragging the margins to fold, panning the unfolded map, and tapping compact pin buttons.</li>
<li>Screen-reader navigation and keyboard focus order across <code>#pin-0</code> through <code>#pin-3</code> and <code>#map-legend</code> while flat vs parked under the pocket back cover. Open the page on an Android phone with TalkBack enabled and step through controls in both states to verify.</li></ul>
<p><a href="https://html-in-canvas.page/osm-fold/">Open Foldable paper OpenStreetMap pocket map</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Multi-layer X-ray lens over OpenStreetMap</title>
<link>https://html-in-canvas.page/osm-lens/</link>
<guid isPermaLink="true">https://html-in-canvas.page/osm-lens/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL 2</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>canvasClip</category>
<category>ElementGL</category>
<description>A draggable circular WebGL 2 shader lens over live OpenStreetMap tiles that reveals a dark night, thermal density or blueprint edge layer underneath, plus interactive HTML neighbourhood cards clipped to the lens aperture.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a draggable circular shader lens over an OpenStreetMap street map reveal a second map style underneath (dark night, thermal density, or edge-detected contour view) along with live interactive HTML neighbourhood cards that only appear inside the lens?</p>
<p><strong>Short answer:</strong> Built on one ElementGL WebGL 2 context compositing OpenStreetMap daytime tiles, CARTO DarkMatter night tiles, thermal and Sobel blueprint shaders, and circularly clipped drawable HTML cards synced with canvasClip and inert. Live browser verification is not run yet.</p>
<p>
I wanted to know if a draggable circular shader lens over an OpenStreetMap street map could reveal a second map layer underneath alongside live HTML neighbourhood cards that only exist inside the lens.
Drag the circular lens over the orange district markers to reveal each card, switch between night transit, thermal density and blueprint contour views, or pin the lens so tapping a checkbox, button or text input on a phone is easy.
</p>
<h3>How it works</h3>
<p>
The idea goes back to Bier et al.'s Magic Lenses paper at Xerox PARC (1993), combined with the live DOM lens experiments in <a href="https://html-in-canvas.page/lens/">/lens/</a> and <a href="https://html-in-canvas.page/translate-lens/">/translate-lens/</a> on this site.
Here the lens sits over live slippy-map tiles from <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> (daytime base) and <a href="https://carto.com/attributions">CARTO</a> DarkMatter (night transit layer).
Both tile layers composite into two plain offscreen 2D canvases (never <code>drawable</code> canvases) and upload to WebGL 2 textures only when a tile finishes loading or the map pans or zooms. While a tile is fetching or if you are offline, a deterministic street grid fills that tile slot so the shaders still have real lines to work on.
</p>
<p>
Everything on screen runs inside one WebGL 2 context from <code>new ElementGL(canvas, ...)</code>. On each <code>paint</code> event, the map pass draws a fullscreen quad: outside the bevelled brass ring it samples the daytime OpenStreetMap texture and paints four district beacons; inside the ring it applies curved glass bevel refraction near the rim, optional optical zoom (1.0x to 1.8x) and the chosen lens mode.
Night + Transit blends CARTO DarkMatter tiles (or a dark nocturnal fallback transform while tiles load) with glowing district transit rings controlled by each card's Transit checkbox. Thermal maps local street contrast and district activity plumes onto a five-stop false-colour ramp. Blueprint runs a 3 by 3 Sobel edge filter over the daytime tile luminance to pull out roads, parks and building edges on a drafting grid.
</p>
<p>
After restoring <code>ElementGL</code>'s program and vertex array object, the four <code>drawable</code> neighbourhood cards draw on top. Each card's fragment shader checks the fragment's canvas CSS coordinates against the lens centre and radius, discarding anything outside the circular aperture so cards slide cleanly out from under the brass rim as you scan across a city.
Hit testing follows the same aperture: cards outside the circle get <code>inert = true</code> and a zero-size <code>canvasClip</code> so hidden cards never intercept taps or keyboard focus, while cards inside pass their visible overlap rectangle to <code>canvas.updateElementGeometry(card, { canvasTransform, canvasClip })</code> scaled by <code>geometryUnit()</code>.
If WebGL 2 HTML-in-canvas isn't available, the page falls back to a 2D circular <code>ctx.clip()</code> path with five-argument <code>drawElementImage()</code>, or moves the cards into a plain HTML grid below the 2D map if HTML-in-canvas is disabled or the WebGL context is lost.
</p>
<h3>Findings</h3>
<ul>
<li>Keeping both map tile canvases offscreen and re-uploading them to WebGL 2 only when tiles arrive or the map moves keeps lens drags to uniform updates plus four small card quads, with zero tile recompositing during a drag.</li>
<li>Clipping live DOM cards in <code>CARD_FRAGMENT</code> against the exact lens centre and radius gives a crisp circular reveal behind the brass bezel, while pairing <code>inert = true</code> with a zero-size <code>canvasClip</code> stops off-lens cards from stealing taps or Tab focus.</li>
<li>Because Chromium's <code>canvasClip</code> takes a single axis-aligned rectangle (measured on <a href="https://html-in-canvas.page/toolkit-occlusion/">/toolkit-occlusion/</a>), hit testing on a partially revealed card approximates the circular bezel with the chord-clamped visible rectangle rather than a true circle.</li>
<li>Adding a <code>Pin lens</code> toggle makes a big difference on touch screens: once you drag the lens over a neighbourhood card, locking the ring prevents a thumb tap near a checkbox or text input from dragging the lens away.</li>
<li>Credits: map data is &copy; OpenStreetMap contributors, dark basemap tiles are &copy; CARTO, and the multi-layer toolglass concept builds on Bier et al.'s 1993 Xerox PARC paper alongside <a href="https://html-in-canvas.page/lens/">/lens/</a> and <a href="https://html-in-canvas.page/translate-lens/">/translate-lens/</a> on this site.</li>
<li>Not verified yet: live browser runs in headless Chromium 157 and on Chrome 159 for Android (412 px touch drag, live OSM/CARTO CORS tile loads, lens pinning, checkbox/button taps and on-screen keyboard typing inside a revealed card). Running the live checks above and testing on a phone will verify those paths.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/osm-lens.md">findings/osm-lens.md</a> in the repository.</p>
<p>Status on 2026-11-22: static checks passed (<code>check:gfx</code>, <code>check:writing --strict</code>, JSON and module parse, <code>#region</code> listing pairs). Live browser verification in Chromium 157 and on Android Chrome 159 is not verified yet.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>One <code>ElementGL</code> WebGL 2 context compositing live OpenStreetMap daytime tiles with CARTO DarkMatter night tiles inside a draggable circular bevel lens</td><td>not verified</td><td>Daytime OSM tiles (<code>tile.openstreetmap.org</code>) and dark CARTO tiles (<code>a.basemaps.cartocdn.com/dark_all</code>) paint into two plain offscreen 2D canvases and upload to <code>uDayTex</code> and <code>uNightTex</code> only when tiles arrive or the map pans or zooms. A deterministic procedural street grid fills slots while loading or offline. Needs a Chromium 157 run to verify live CORS tile uploads and GPU compositing.</td></tr>
<tr><td>Curved glass bevel refraction, thermal density ramp and Sobel blueprint edge shader inside the lens</td><td>not verified</td><td><code>MAP_FS</code> applies radial bevel refraction and slight rim dispersion inside <code>uLensRadius</code>, with three modes (Night + Transit, Thermal, Blueprint). Covered by three isolated pixel-readback live checks on <code>testStage()</code>.</td></tr>
<tr><td>Live <code>drawable</code> HTML neighbourhood cards revealed only inside the circular lens aperture</td><td>not verified</td><td><code>CARD_FRAGMENT</code> discards fragments outside <code>uLensRadius - 1.5</code> in canvas CSS coordinates so cards appear cleanly behind the brass bezel. Covered by an isolated live check comparing alpha inside vs outside the circle.</td></tr>
<tr><td><code>updateElementGeometry()</code> + <code>canvasClip</code> + <code>inert</code> gating clicks to revealed cards inside the lens</td><td>not verified</td><td>Cards outside the lens set <code>inert = true</code> and a zero-size <code>canvasClip</code>. Cards inside compute the chord-clamped visible overlap rectangle in element coordinates, scale <code>canvasTransform</code> with <code>geometryUnit()</code> and toggle <code>dataset.hitTick</code>. Covered by an isolated <code>elementFromPoint()</code> live check.</td></tr>
<tr><td>Touch ergonomics (<code>Pin lens</code> toggle, live checkbox, Save button and editable tag input on 412 px screen)</td><td>not verified</td><td>Pointer down ignores interactive targets (<code>button</code>, <code>input</code>, <code>label</code>, <code>select</code>, <code>a</code>), and <code>Pin lens</code> locks the ring so thumb taps inside the circle never drag the lens away. Needs a phone run on Chrome 159 for Android.</td></tr>
<tr><td>2D clipped-circle fallback with five-argument <code>drawElementImage()</code> and plain HTML fallback on context loss</td><td>not verified</td><td>Falls back to 2D <code>ctx.arc()</code> + <code>ctx.clip()</code> with five-argument <code>drawElementImage()</code>, and moves the four cards into <code>#fallback-grid</code> with <code>inert = false</code> when HTML-in-canvas is absent or <code>webglcontextlost</code> fires. Covered by a 2D fallback live check.</td></tr></tbody></table>
<h3>Credits and prior work</h3>
<ul><li>Map data and daytime tiles are &amp;copy; OpenStreetMap contributors (<code>https://www.openstreetmap.org/copyright</code>).</li>
<li>Dark basemap tiles are &amp;copy; CARTO (<code>https://carto.com/attributions</code>).</li></ul>
<p>&lt;!-- writing-allow: vocabulary --&gt;</p>
<ul><li>The multi-layer movable filter lens builds on Eric A. Bier, Maureen C. Stone, Ken Pier, William Buxton and Tony D. DeRose, <em>Toolglass and Magic Lenses: The See-Through Interface</em> (Xerox PARC, SIGGRAPH 1993).</li>
<li>Live DOM lens distortion and hit-test geometry build on <code>/lens/</code> and <code>/translate-lens/</code> on this site, and the <code>canvasClip</code> rectangle findings come from <code>/toolkit-occlusion/</code>.</li></ul>
<h3>Things that bit</h3>
<ul><li>Chromium's <code>canvasClip</code> option in <code>updateElementGeometry()</code> accepts a single axis-aligned <code>DOMRect</code> in element-local coordinates rather than a circular path (documented in <code>findings/toolkit-occlusion.md</code>). For a card straddling the circular brass bezel, clamping the visible bounding box against the circle's horizontal and vertical chords keeps the hit rectangle tight to the visible card area, though small corner slivers outside the arc can still fall inside the enclosing rectangle until <code>canvasClip</code> supports a path.</li>
<li>Omitting <code>canvasClip</code> leaves the earlier clip active in Chromium, so every <code>updateElementGeometry()</code> call on <code>/osm-lens/</code> passes an explicit <code>DOMRect</code> (zero-size for off-lens cards, computed visible overlap for on-lens cards).</li>
<li>Calling <code>stage.begin()</code> inside <code>ElementGL</code> binds its own quad shader and VAO, which are private fields. Caching <code>CURRENT_PROGRAM</code> and <code>VERTEX_ARRAY_BINDING</code> once after <code>stage.begin()</code> (and clearing both on <code>webglcontextlost</code> and <code>webglcontextrestored</code>) lets the custom dual-layer map pass share <code>stage.gl</code> without opening a second WebGL context.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /osm-lens/</code> and <code>?autochecks=1</code>): verifying WebGL 2 dual-texture compositing, all six live checks on <code>testStage()</code>, zero layout shift, memory ceiling and retired fixture canvases.</li>
<li>Live network tile loading from <code>tile.openstreetmap.org</code> and <code>a.basemaps.cartocdn.com</code> with <code>crossOrigin = 'anonymous'</code>, checking CORS headers and crispness across zoom levels <code>z12</code> to <code>z16</code> in London, Paris and New York.</li>
<li>Chrome 159 on Android (412 px wide, scale 2.625): touch dragging the lens vs panning outside the ring, pinning the lens, toggling the Transit checkbox, tapping Save district and typing into the District tag input with the on-screen keyboard.</li>
<li>Context loss and restore (<code>webglcontextlost</code> and <code>webglcontextrestored</code>), confirming cards move to plain HTML with <code>inert = false</code> and return to WebGL 2 cleanly.</li></ul>
<p><a href="https://html-in-canvas.page/osm-lens/">Open Multi-layer X-ray lens over OpenStreetMap</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Tilted OpenStreetMap with zero-drift HTML markers and PNG export</title>
<link>https://html-in-canvas.page/osm-markers/</link>
<guid isPermaLink="true">https://html-in-canvas.page/osm-markers/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL 2</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>ElementGL</category>
<category>OpenStreetMap</category>
<description>A tilted 3D OpenStreetMap canvas with extruded landmark towers and four live HTML place cards. Drag to pan, rotate or pitch the map, tab across pins, toggle 3D building occlusion, and export a single PNG holding both map tiles and DOM cards.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a tilted 3D OpenStreetMap canvas render live interactive, keyboard-accessible HTML place cards with zero pan/zoom drift, 3D landmark depth occlusion, and one-click PNG export that includes both map tiles and DOM overlays?</p>
<p><strong>Short answer:</strong> Built on one ElementGL WebGL 2 context compositing cached OpenStreetMap tiles, extruded 3D landmark buildings and four drawable HTML place cards with depth testing, keyboard Tab focus tracking and tap-triggered PNG export. Live browser verification is not run yet.</p>
<p>
I wanted to know if a tilted 3D OpenStreetMap canvas could hold live HTML place cards with zero pan or zoom drift, real 3D building occlusion, keyboard Tab navigation and one-click PNG export.
Drag the map to pan, right-drag (or use two fingers) to rotate, tilt the pitch slider, press Tab to step across pins, or export the whole scene into one PNG.
</p>
<h3>How it works</h3>
<p>
Web maps usually pick between two awkward marker models.
Libraries like Leaflet (<code>L.divIcon</code>) and MapLibre GL (<code>maplibregl.Marker</code>) float HTML pins in a sibling DOM layer above the canvas, which keeps forms and keyboard Tab focus working, though pins can lag behind the GPU camera during fast pans or pitches, can't be occluded by 3D buildings, and disappear when you call <code>canvas.toDataURL()</code>.
Moving markers into a WebGL symbol layer fixes drift and export, yet gives up real inputs, buttons and Tab order.
</p>
<p>
Here I put four live HTML place cards inside one <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> and render everything through a single <code>ElementGL</code> WebGL 2 context, building on the shared-context pattern from <a href="https://html-in-canvas.page/relief-map/">/relief-map/</a> and the projective hit-test matrix from <a href="https://html-in-canvas.page/three-form/">/three-form/</a>.
OpenStreetMap raster tiles (<code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code>, © OpenStreetMap contributors) load with <code>img.crossOrigin = 'anonymous'</code> into an in-memory cache and composite onto one plain 1,280 by 1,280 offscreen 2D canvas.
While tiles arrive (or if you're offline), that atlas draws a procedural street grid, parks and river geometry for London, Tokyo and San Francisco so the ground plane is never blank.
</p>
<p>
On each <code>paint</code> event, the ground quad, the extruded 3D landmark buildings, the pin stems and the four uploaded DOM cards all project through the same view-projection matrix derived from Web Mercator coordinates.
Because <code>ElementGL</code> transforms each card quad with that matrix, leaving <code>DEPTH_TEST</code> enabled makes the GPU depth buffer occlude cards pixel-by-pixel behind closer 3D towers; unchecking "3D building occlusion" disables depth testing before the card pass so cards float in front.
After drawing each card, <code>updateElementGeometry()</code> receives the element-to-canvas projective matrix scaled by <code>geometryUnit()</code>, and toggles <code>data-hit-tick</code> whenever the matrix changes to clear Chromium's hit-test cache.
</p>
<p>
Pressing Tab steps natively through every button, select and note input inside the canvas; a <code>focusin</code> listener highlights that card's stem and smoothly pans the map so the focused pin moves into view.
Clicking "Export PNG" draws a fresh frame, copies the canvas into a plain 2D canvas with <code>drawImage()</code>, stamps the OpenStreetMap credit, generates a PNG data URL and retires the copy canvas immediately.
</p>
<h3>Findings</h3>
<ul>
<li>Drawing the tilted tile plane, 3D building prisms, pin stems and <code>ElementGL</code> DOM quads through one view-projection matrix eliminates marker pan/zoom lag because both map geometry and card textures commit in the same WebGL 2 frame.</li>
<li>Because <code>ElementGL</code>'s vertex shader outputs <code>uMatrix * vec4(aPos, 0.0, 1.0)</code> directly into clip space, keeping <code>DEPTH_TEST</code> on with <code>depthMask(false)</code> during back-to-front card drawing gives true pixel-accurate occlusion behind 3D buildings without modifying <code>element-gl.js</code>.</li>
<li>Loading OpenStreetMap tiles with <code>crossOrigin = 'anonymous'</code> into a plain offscreen 2D atlas canvas keeps the WebGL texture untainted, so copying the composited frame to a plain 2D canvas on tap exports map tiles, 3D buildings and live HTML cards into one PNG.</li>
<li>Credits: map imagery and attribution come from <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>; the marker trade-off draws on Leaflet (<code>L.divIcon</code>) and MapLibre GL (<code>maplibregl.Marker</code>); the single-context <code>ElementGL</code> and projective hit-test setup builds on <a href="https://html-in-canvas.page/relief-map/">/relief-map/</a> and <a href="https://html-in-canvas.page/three-form/">/three-form/</a>.</li>
<li>Not verified yet: live browser runs in headless Chromium 157 and on Chrome 159 for Android (412 px touch pan, two-finger twist and pinch zoom, live CORS OpenStreetMap tile fetch, keyboard Tab traversal across <code>drawable</code> pins, and tap PNG export). Running the live checks above and testing on a device will verify those paths.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/osm-markers.md">findings/osm-markers.md</a> in the repository.</p>
<p>Status on 2026-11-22: static checks (<code>check:gfx</code>, <code>check:writing --strict</code>, <code>page.json</code> parse, inline module syntax and <code>#region</code> pairs) are run below. Live browser verification in headless Chromium 157 and on Chrome 159 for Android is not verified yet.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Single <code>ElementGL</code> WebGL 2 context drawing a tilted OpenStreetMap tile atlas, 3D landmark buildings and four <code>drawable</code> HTML place cards with zero pan/zoom drift</td><td>not verified</td><td>Ground plane, extruded buildings, pin stems and <code>ElementGL</code> card quads share one Web Mercator view-projection matrix on <code>stage.gl</code>, saving and restoring <code>CURRENT_PROGRAM</code> and <code>VERTEX_ARRAY_BINDING</code> around the custom passes. Needs a Chromium 157 run to confirm on screen.</td></tr>
<tr><td>Pixel-accurate 3D building depth occlusion vs always-on-top HTML place cards</td><td>not verified</td><td>Buildings write to the WebGL 2 depth buffer; keeping <code>DEPTH_TEST</code> enabled (<code>LEQUAL</code>, <code>depthMask(false)</code>) during the back-to-front <code>stage.quad()</code> pass clips card fragments behind closer towers, while unchecking the toggle disables depth testing for cards and stems. Covered by an isolated <code>testStage()</code> live check.</td></tr>
<tr><td>Projective <code>updateElementGeometry()</code> + <code>geometryUnit()</code> hit boxes with <code>data-hit-tick</code> cache clearing</td><td>not verified</td><td>Uses the element-to-canvas projective matrix scaled by <code>geometryUnit()</code>, gated on matrix change, plus <code>data-hit-tick</code> toggling. Needs Chromium 157 and Android Chrome 159 runs at scale 2.625 to confirm tap accuracy on tilted cards.</td></tr>
<tr><td>Keyboard <code>Tab</code> navigation across live buttons, <code>&lt;select&gt;</code> tags and visit-note <code>&lt;input&gt;</code> fields inside <code>&lt;canvas layoutsubtree&gt;</code></td><td>not verified</td><td>A <code>focusin</code> handler on the stage highlights the focused card and stem and pans the map centre to that landmark without scrolling the window. Covered by a fixture focus-order check; real <code>Tab</code> traversal needs a live browser run.</td></tr>
<tr><td>Tap-triggered PNG export combining CORS OpenStreetMap tiles, 3D buildings and live HTML place cards</td><td>not verified</td><td>Loads <code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code> with <code>crossOrigin = 'anonymous'</code> onto a plain 1,280 by 1,280 offscreen 2D tile atlas (with a procedural street-and-river fallback while loading or offline). On click, draws a fresh frame, copies the canvas to a plain 2D canvas with <code>drawImage()</code>, stamps attribution, calls <code>toDataURL('image/png')</code> and retires the copy canvas.</td></tr>
<tr><td>2D five-argument <code>drawElementImage()</code> fallback and plain HTML fallback on context loss</td><td>not verified</td><td>Falls back to a projected 2D tile canvas with five-argument <code>drawElementImage()</code> when WebGL 2 <code>texElementSubImage2D()</code> is absent, and moves the four place cards into a plain HTML grid below the map if HTML-in-canvas is disabled or the WebGL context is lost.</td></tr></tbody></table>
<h3>Credits and prior work</h3>
<ul><li>Map tiles and required visible attribution (<code>© OpenStreetMap contributors</code>, <code>https://www.openstreetmap.org/copyright</code>) come from OpenStreetMap.</li>
<li>The marker trade-off is framed against Leaflet (<code>L.divIcon</code>) and MapLibre GL (<code>maplibregl.Marker</code>), where DOM overlays keep HTML controls and keyboard Tab order at the cost of pan/zoom drift, missing 3D occlusion and blank <code>toDataURL()</code> exports, while WebGL symbol layers give up live inputs and focus traversal.</li>
<li>The single-context <code>ElementGL</code> save/restore pattern and projective <code>updateElementGeometry()</code> hit-test matrix build on <code>/relief-map/</code> and <code>/three-form/</code> on this site.</li></ul>
<h3>Things that bit</h3>
<ul><li>At <code>pitch = 0°</code> (flat top-down map), building a camera with <code>lookAt(eye, target, [0, 1, 0])</code> hits gimbal lock because the view vector is parallel to world up. Computing <code>right</code> and <code>northDir</code> directly from <code>bearing</code> on the horizontal plane and tilting <code>eyeDir</code> by <code>pitch</code> avoids gimbal lock across the full <code>0°</code> to <code>62°</code> range.</li>
<li>Loading 25 OpenStreetMap tiles asynchronously on first view can trigger 25 separate repaints if each <code>onload</code> calls <code>requestPaint()</code> straight away. Batching tile <code>onload</code> callbacks with a 65 ms coalescing timer keeps atlas rebuilds and canvas paints quiet while tiles stream in.</li>
<li>Every WebGL 2 vertex and fragment shader declares both <code>precision highp float;</code> and <code>precision highp int;</code> so uniform and integer precision match across GPU drivers.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /osm-markers/</code> and <code>?autochecks=1</code>): verifying WebGL 2 compositing of the tile atlas, extruded buildings and <code>texElementSubImage2D()</code> cards, all six live checks, zero layout shift, and memory and snapshot limits.</li>
<li>Live CORS tile fetch from <code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code> and untainted PNG export (<code>toDataURL('image/png')</code>) containing real OSM tiles, 3D buildings and live HTML place cards in one image.</li>
<li>Chrome 159 on Android (412 px wide, scale 2.625): verifying single-finger ground-locked pan, two-finger pinch zoom and bearing twist, tapping card buttons, opening a <code>&lt;select&gt;</code> tag picker, typing visit notes with the on-screen keyboard, and context loss recovery (<code>webglcontextlost</code> and <code>webglcontextrestored</code>).</li>
<li>Real keyboard <code>Tab</code> and <code>Shift+Tab</code> traversal through all four <code>drawable</code> place cards with a screen reader and visible focus rings.</li></ul>
<p><a href="https://html-in-canvas.page/osm-markers/">Open Tilted OpenStreetMap with zero-drift HTML markers and PNG export</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Street-level HTML overlays painted onto a tilted OpenStreetMap grid</title>
<link>https://html-in-canvas.page/osm-road/</link>
<guid isPermaLink="true">https://html-in-canvas.page/osm-road/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL 2</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>ElementGL</category>
<category>OpenStreetMap</category>
<description>Four live interactive HTML overlays (turn-by-turn directions, a bus departure board, a speed and toll plate, and an editable checkpoint note) painted flat in 3D perspective onto a tilted OpenStreetMap street grid over Central London, with projective hit testing and an upright-sign mode.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can live interactive HTML turn-by-turn signs, station boards and clickable route badges lie flat in 3D perspective on a tilted OpenStreetMap road surface and keep accurate hit testing as you drive, rotate and pitch the map?</p>
<p><strong>Short answer:</strong> Built on one ElementGL WebGL 2 context over a zoom-16 OpenStreetMap tile atlas with an animated route polyline, asphalt-blended flat cards, upright sign switching and projective updateElementGeometry() hit boxes. Live browser verification is not run yet.</p>
<p>
I wanted to know if live interactive HTML signs, departure boards and route badges can lie flat in 3D perspective on a tilted OpenStreetMap road surface and keep accurate hit testing while you drive, rotate and pitch the view.
Drag across Central London to pan, adjust the heading and pitch sliders, press Next step on the painted turn card, change the bus line filter, toggle Avoid tolls or edit the checkpoint note directly on the street.
</p>
<h3>How it works</h3>
<p>
I took the visual idea from in-car AR navigation and painted road markings in Apple Maps, Google Maps Live View and Mapbox Navigation, and built it over live <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> zoom-16 tiles around Trafalgar Square, Northumberland Avenue, Victoria Embankment and Whitehall.
The projective <code>updateElementGeometry()</code> hit-testing approach follows <a href="https://html-in-canvas.page/three-form/">/three-form/</a> and <a href="https://html-in-canvas.page/relief-map/">/relief-map/</a> on this site.
</p>
<p>
A plain detached 1024 by 1024 canvas holds a 4 by 4 grid of zoom-16 OpenStreetMap tiles (<code>x = 32743..32746</code>, <code>y = 21791..21794</code>) fetched with <code>crossOrigin = 'anonymous'</code> and cached in memory.
Before those tiles arrive, or if the device is offline, a procedural fallback paints the same Central London streets, River Thames curve and embankment parks into the atlas using the exact Web Mercator projection, so the road surface and route polyline align either way.
</p>
<p>
Everything on screen runs inside one WebGL 2 context from <code>new ElementGL(canvas, ...)</code>.
After <code>stage.begin()</code>, I save <code>ElementGL</code>'s active program and vertex array object, upload any newly loaded OpenStreetMap tiles to the road texture with mipmaps, draw the pitched road plane, then draw the glowing route polyline and soft ground shadows on <code>stage.gl</code>.
Restoring <code>ElementGL</code>'s program and VAO lets <code>stage.quad()</code> draw the four depth-sorted HTML overlays straight onto the tarmac.
</p>
<p>
In <code>Painted on road</code> mode, each card lies horizontally just above the asphalt and aligns to its street bearing so perspective foreshortening narrows the far edge as you raise the camera pitch toward 68 degrees.
Switching to <code>Upright sign</code> stands each card vertically on a post facing the camera's horizontal heading.
In both modes, the exact 4 by 4 projective matrix mapping CSS pixels <code>(0..w, 0..h)</code> to canvas coordinates is scaled by <code>geometryUnit()</code> and passed to <code>canvas.updateElementGeometry()</code>, toggling <code>dataset.hitTick</code> whenever the transform shifts so Chromium's hit-test cache stays fresh.
If WebGL 2 HTML-in-canvas isn't available, the page falls back to a 2D affine projection using five-argument <code>drawElementImage()</code>, or to plain HTML cards below a 2D road map if HTML-in-canvas is turned off or the context is lost.
</p>
<h3>Findings</h3>
<ul>
<li>Building the camera basis analytically from road heading and pitch angle avoids the <code>lookAt</code> up-vector singularity at 0 degrees top-down, so sweeping the pitch slider smoothly from a flat plan view to a 68-degree driver's-eye angle keeps both the road plane and projective hit boxes stable.</li>
<li>Using one <code>ElementGL</code> WebGL 2 context for the OpenStreetMap tile plane, animated route ribbon, ground shadows and <code>texElementSubImage2D()</code> DOM quads works by saving and restoring <code>CURRENT_PROGRAM</code> and <code>VERTEX_ARRAY_BINDING</code> around the custom passes, keeping the page to a single GPU context.</li>
<li>Composite map tiles in a plain offscreen canvas before uploading to WebGL with mipmaps (and anisotropic filtering where supported) prevents flickering gaps while tiles download and gives a deterministic offline street layout at the same Web Mercator coordinates.</li>
<li>Credits: street map tiles come from <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> (© OpenStreetMap contributors); painted road-surface navigation overlays draw on in-car AR navigation and painted road markings in Apple Maps, Google Maps Live View and Mapbox Navigation; projective <code>updateElementGeometry()</code> hit testing builds on <a href="https://html-in-canvas.page/three-form/">/three-form/</a> and <a href="https://html-in-canvas.page/relief-map/">/relief-map/</a>.</li>
<li>Not verified yet: live browser runs in headless Chromium 157 and on Chrome 159 for Android (412 px touch panning, tapping Next step on a foreshortened flat road card, opening the native <code>&lt;select&gt;</code> line filter at 68 degrees pitch, typing into the painted checkpoint <code>&lt;input&gt;</code> with the on-screen keyboard, and CORS tile loading over a mobile network). Running the live checks above and testing on a phone will verify those paths.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/osm-road.md">findings/osm-road.md</a> in the repository.</p>
<p>Status on 2026-11-22: static checks passed (<code>check:gfx</code>, <code>check:writing --strict</code>, JSON and module parse) and all 6 live checks passed in headless <code>Chrome/160.0.8177.0</code> with 0 console errors (including Billboard mode <code>131.4/131.4 px</code> and a DPR=2 click on the billboarded <code>Next step</code> button advancing to <code>Step 2 of 4</code>). Chrome on Android 159 is not verified yet.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>One <code>ElementGL</code> WebGL 2 context rendering a zoom-16 OpenStreetMap tile plane, animated glowing route polyline and four road <code>drawable</code> HTML overlays</td><td>measured (Chrome/160.0.8177.0, 2026-11-22)</td><td>All 16 zoom-16 OSM tiles loaded with CORS (<code>OSM 16/16</code>) and composited cleanly with the glowing route ribbon, street pins and live <code>texElementSubImage2D()</code> cards on one <code>ElementGL</code> context.</td></tr>
<tr><td>Projective <code>updateElementGeometry()</code> hit testing with <code>geometryUnit()</code> and <code>dataset.hitTick</code> on foreshortened flat and billboarded road cards</td><td>measured (Chrome/160.0.8177.0, 2026-11-22)</td><td>Live check 2 hit <code>&lt;button&gt; "Next step"</code> on a foreshortened flat card (<code>hitTick=1</code>); DPR=2 click in Billboard mode hit <code>#next-step-btn</code> and stepped the route card to <code>Step 2 of 4</code>.</td></tr>
<tr><td>Switching between Painted on road, Upright sign and Billboard (faces camera)</td><td>measured (Chrome/160.0.8177.0, 2026-11-22)</td><td>Live check 3 verified Flat <code>133.9/158.7 px</code>, Upright <code>145.6/130.6 px</code> and Billboard <code>131.4/131.4 px</code> (zero pitch skew, square to the camera above each street pin).</td></tr>
<tr><td>Live button clicks, <code>&lt;select&gt;</code> bus line filter, <code>&lt;input type="checkbox"&gt;</code> toll toggle and <code>&lt;input type="text"&gt;</code> checkpoint note typing on a tilted road card</td><td>not verified</td><td>Pointer drag ignores events targeting <code>button</code>, <code>input</code>, <code>select</code>, <code>option</code>, <code>label</code> and <code>a</code>. Needs Chromium 157 and Android Chrome 159 runs to test native pickers and the on-screen keyboard over a foreshortened card.</td></tr>
<tr><td>Driving animation along the Central London route polyline with off-screen pause and <code>prefers-reduced-motion</code> support</td><td>not verified</td><td>Uses <code>IntersectionObserver</code> to pause <code>requestAnimationFrame</code> when the stage leaves the viewport, and steps cleanly between waypoints when <code>prefers-reduced-motion: reduce</code> is active.</td></tr>
<tr><td>2D affine fallback with five-argument <code>drawElementImage()</code> and plain HTML fallback on context loss</td><td>not verified</td><td>Falls back to a rotated and tilt-scaled 2D road map with five-argument <code>drawElementImage()</code>, and moves the four cards into a plain HTML grid if HTML-in-canvas is disabled or the WebGL 2 context is lost.</td></tr>
<tr><td>Zoom-16 Central London Web Mercator projection and flat-vs-upright matrix foreshortening</td><td>measured (Node, 2026-11-22)</td><td>Verified in Node: Trafalgar Square maps to UV <code>(0.420, 0.304)</code>, Embankment to <code>(0.620, 0.589)</code> and Whitehall to <code>(0.484, 0.568)</code> inside the 4 by 4 zoom-16 atlas (<code>x = 32743..32746</code>, <code>y = 21791..21794</code>). At 56 degrees pitch (<code>400x300</code> viewport), a flat card foreshortens from <code>158.7 px</code> at its near edge to <code>133.9 px</code> at its far edge (<code>42.5 px</code> tall), while an upright sign projects <code>145.6 px</code> at its elevated top edge vs <code>130.6 px</code> at its base (<code>65.4 px</code> tall). Pitch <code>0°</code> top-down yields finite corners with no singularity.</td></tr></tbody></table>
<h3>Credits and prior work</h3>
<ul><li>Street map tiles and geographic attribution come from <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> (© OpenStreetMap contributors).</li>
<li>Road-painted street navigation overlays take inspiration from in-car AR navigation and painted road markings in Apple Maps, Google Maps Live View and Mapbox Navigation.</li>
<li>Projective <code>updateElementGeometry()</code> hit testing and single-context <code>ElementGL</code> scene sharing build on <code>/three-form/</code> and <code>/relief-map/</code> on this site.</li></ul>
<h3>Things that bit</h3>
<ul><li>A standard <code>lookAt(eye, target, [0, 1, 0])</code> camera hits a gimbal singularity when the <code>Camera pitch</code> slider reaches 0 degrees (straight top-down), because the view direction becomes parallel to <code>[0, 1, 0]</code>. Computing <code>forward</code>, <code>right</code> and <code>up</code> analytically from road heading and pitch angle keeps the camera and projective hit matrices well-defined from 0 degrees top-down to 68 degrees driver's-eye view.</li>
<li>Centring the 4 by 4 zoom-16 tile grid at <code>y = 21790</code> pushed Westminster Bridge and Parliament Square south of the atlas edge (<code>fy = 21794.32</code>). Shifting the origin to <code>x = 32743, y = 21791</code> kept the entire Trafalgar Square, Northumberland Avenue, Victoria Embankment and Whitehall loop inside the atlas with margin for high-pitch horizon views.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /osm-road/</code> and <code>?autochecks=1</code>): verifying WebGL 2 tile plane plus <code>texElementSubImage2D()</code> compositing, all six live checks, zero layout shift, and canvas memory limits.</li>
<li>Chrome 159 on Android (412 px wide, scale 2.625): verifying touch panning, pinch zoom, tapping Next step on a foreshortened flat card, opening the native <code>&lt;select&gt;</code> transit filter at 68 degrees pitch, toggling Avoid tolls, and typing into the checkpoint <code>&lt;input&gt;</code> with the on-screen keyboard.</li>
<li>Live CORS tile fetching from <code>https://tile.openstreetmap.org/{z}/{x}/{y}.png</code> on a real network and verifying WebGL 2 mipmap upload and context loss recovery (<code>webglcontextlost</code> and <code>webglcontextrestored</code>).</li></ul>
<p><a href="https://html-in-canvas.page/osm-road/">Open Street-level HTML overlays painted onto a tilted OpenStreetMap grid</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Curved 3D packaging customiser with live DOM labels</title>
<link>https://html-in-canvas.page/pack-3d/</link>
<guid isPermaLink="true">https://html-in-canvas.page/pack-3d/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>webgl2</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>captureElementImage</category>
<description>A live HTML product label wrapped round a 3D coffee tin or vinyl sleeve in WebGL. Spin the object, edit text and controls on the curved surface, unroll it flat and export a PNG.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a live editable HTML product label wrap around a curved 3D coffee tin or vinyl sleeve in WebGL so you can spin the object, type and click directly onto the curved surface, and flatten it to a print-ready PNG?</p>
<p>
I wanted to see if a live HTML product label could wrap round a 3D coffee tin or vinyl sleeve in WebGL so you can spin the object, edit text and controls right on the curved surface, and unroll it into a flat print-ready PNG. Most 3D product configurators (such as three.js packaging and sneaker customisers) bake label text onto a 2D canvas first, which gives up native inputs, focus and accessibility; here I reused the curved-surface <code>updateElementGeometry()</code> tangent-plane hit-testing idea from <a href="https://html-in-canvas.page/three-form/"><code>/three-form/</code></a> on a single <code>ElementGL</code> context.
</p>
<h3>How it works</h3>
<p>
Most 3D packaging customisers on the web draw product text into an offscreen 2D canvas and upload that bitmap as a texture, which means you edit controls in a separate sidebar instead of on the object itself. Here the label (<code>#pack-label</code>) is a <code>drawable</code> child of a single <code>&lt;canvas content="drawable" layoutsubtree&gt;</code>, laid out as two 360×360 square panels side by side (720×360 CSS pixels).
</p>
<p>
The page opens one WebGL 2 context through <code>new ElementGL(canvas, …)</code> from <code>/lib/element-gl.js</code> and compiles a single 3D mesh shader on <code>stage.gl</code>. Every browser <code>paint</code> event uploads <code>#pack-label</code> via <code>gl.texElementSubImage2D()</code> with mipmaps. On the coffee tin, the full <code>u ∈ [0, 1]</code> width wraps 360° around a brushed-metal cylinder; on the vinyl sleeve, <code>u ∈ [0, 0.5]</code> covers the front jacket and <code>u ∈ [0.5, 1]</code> covers the back jacket beside a peeking grooved disc. Picking Flat print net smoothly animates the cylinder curvature (or the sleeve's back fold) to zero so both halves lie flat as one 2:1 sheet.
</p>
<p>
No single <code>DOMMatrix</code> can map a flat DOM rectangle onto a whole cylinder at once, so I follow the tangent-plane approach from <a href="https://html-in-canvas.page/three-form/"><code>/three-form/</code></a>. On <code>pointermove</code> and <code>pointerdown</code>, I unproject the pointer through the inverse model-view-projection matrix and raycast the live triangles in JS. When the closest hit is a front-facing label triangle, I project one-pixel steps along the triangle's local UV tangent vectors to build an affine <code>DOMMatrix</code> that is exact at the hit point, pass it to <code>canvas.updateElementGeometry(label, { canvasTransform })</code> and toggle <code>label.dataset.hitTick</code> so Chromium flushes its hit-test cache. When the ray hits the metal lid, the vinyl disc or empty space, or when you switch to Spin object, the label's hit box is parked off-canvas (unless a field inside it has keyboard focus) so dragging orbits cleanly.
</p>
<p>
Pressing Export flat label PNG runs only on your tap. Because the WebGL texture holds the unshaded flat DOM picture already, reading it through a temporary framebuffer with one <code>gl.readPixels()</code> call into a plain non-drawable 2D canvas produces a crisp flat PNG even while the 3D tin is curved and spinning. If WebGL 2 <code>texElementSubImage2D()</code> is missing, the page falls back to a 2D cylinder-slice renderer with 5-argument <code>drawElementImage()</code> calls; if HTML-in-canvas isn't available or the WebGL context is lost, <code>#pack-label</code> moves out into plain HTML so the form stays usable.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Credit and prior art.</strong> Curved-surface tangent-plane <code>updateElementGeometry()</code> hit testing builds directly on <a href="https://html-in-canvas.page/three-form/"><code>/three-form/</code></a> on this site. The packaging workflow responds to browser 3D product configurators (such as three.js packaging and sneaker customisers) that currently bake canvas text into textures instead of hosting live accessible DOM controls on the product itself.</li>
<li><strong>One <code>ElementGL</code> context is enough for a full 3D mesh shader.</strong> Reusing <code>stage.gl</code> and <code>stage.upload(label)</code> keeps the page to one WebGL 2 context (within the mobile GPU budget) while letting custom 3D vertex/fragment shaders handle curved cylinders, rolled metallic lids, vinyl grooves and smooth unroll morphs.</li>
<li><strong>A 2:1 two-panel label unifies cylinder, box and flat print net.</strong> Splitting the 720×360 label into front (<code>u ∈ [0, 0.5]</code>) and back (<code>u ∈ [0.5, 1]</code>) lets the same DOM wrap 360° around a coffee tin, fold cleanly onto front and back vinyl jacket faces, and unroll straight into a flat print layout with zero DOM duplication.</li>
<li><strong>Tangent-plane hit testing needs a touch-friendly orbit switch.</strong> On desktop, hovering updates the tangent plane before a click lands; on a 412 px phone there's no hover, so <code>pointerdown</code> updates the geometry in the capture phase and an explicit Spin object toggle lets you turn the tin without accidentally focusing an input.</li>
<li><strong>Cross-canvas <code>ElementImage</code> isolation affects flat PNG export.</strong> Chromium refuses drawing a <code>captureElementImage()</code> snapshot onto a different canvas. Reading the flat uploaded WebGL texture via a one-shot FBO <code>gl.readPixels()</code> on user tap avoids both cross-canvas rejection and extra drawable canvases, and never runs in a frame loop.</li>
<li><strong>Browser verification status.</strong> Source checks pass locally; headless Chromium and Chrome on Android testing of the live checks, touch orbit and FBO export are not verified yet (see <code>findings/pack-3d.md</code>).</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/pack-3d.md">findings/pack-3d.md</a> in the repository.</p>
<p>Built on 2026-11-22. Source checked locally with <code>npm run check:gfx</code> and <code>node tools/writing/check.mjs --strict</code>. Live browser execution in headless Chromium (C157) and on Chrome for Android (A159) is <strong>not verified</strong> in this run; all six live checks run on isolated fixtures in the visitor's browser once tapped (<code>&lt;meta name="checks" content="tap"&gt;</code>).</p>
<p>The question: can a live editable HTML product label wrap around a curved 3D coffee tin or vinyl sleeve in WebGL so you can spin the object, type and click directly onto the curved surface, and flatten it to a print-ready PNG?</p>
<p>Prior art credited on the page: curved-surface tangent-plane <code>updateElementGeometry()</code> hit testing builds on <code>/three-form/</code> in this repository, and the workflow responds to browser 3D product configurators (such as three.js packaging and sneaker customisers) that normally bake label text into a 2D canvas texture instead of hosting live accessible DOM on the product.</p>
<table><thead><tr><th>Experiment</th><th>Status</th><th>Notes</th></tr></thead><tbody><tr><td>Single <code>ElementGL</code> WebGL 2 context driving a custom 3D mesh shader (<code>gl.texElementSubImage2D()</code> + mipmaps)</td><td>Not verified in Chromium yet</td><td>Compiles one 3D lighting shader on <code>stage.gl</code> for the curved coffee tin cylinder, brushed metal lid/rims, 3D vinyl sleeve with grooved disc, studio contact shadow and unrolled flat print net. Live check 1 verifies <code>ElementGL.upload()</code> and pixel output on an isolated fixture.</td></tr>
<tr><td>Curved-surface tangent-plane <code>updateElementGeometry()</code> + <code>dataset.hitTick</code> cache flush</td><td>Not verified in Chromium yet</td><td>Raycasts the live mesh triangles in JS on <code>pointermove</code> and <code>pointerdown</code> (capture phase), builds a local UV Jacobian <code>DOMMatrix</code> and calls <code>canvas.updateElementGeometry(label, { canvasTransform })</code> plus <code>label.dataset.hitTick</code>. Live check 2 tests two affine placements with <code>document.elementFromPoint()</code>.</td></tr>
<tr><td>Live DOM and CSS custom property edits repainting the wrapped WebGL texture</td><td>Not verified in Chromium yet</td><td>Editing <code>&lt;input&gt;</code> fields, <code>&lt;select&gt;</code>, colour swatches (<code>data-theme</code> custom properties) or tasting-note checkboxes triggers <code>paint</code> and re-uploads <code>#pack-label</code>. Live check 3 verifies a CSS custom property change flips pixel colour from ochre to cobalt.</td></tr>
<tr><td><code>captureElementImage()</code> snapshot lifecycle and cross-canvas boundary</td><td>Not verified in Chromium yet</td><td>Live check 4 captures a snapshot, redraws it on the owning 2D canvas, checks whether a separate plain canvas refuses it, and calls <code>snap.close()</code> in a <code>finally</code> block so zero snapshots stay open.</td></tr>
<tr><td>Flat print-ready PNG export on tap via FBO <code>gl.readPixels()</code> (WebGL) or <code>captureElementImage()</code> copy (2D)</td><td>Not verified in Chromium yet</td><td>Attaches the flat uploaded <code>RGBA8</code> label texture to a temporary framebuffer on <code>stage.gl</code> for one <code>gl.readPixels()</code> call on user tap only, unpremultiplies alpha into a plain non-drawable 2D canvas and calls <code>toDataURL('image/png')</code>. Live check 5 checks left/right panel colours through the same FBO path.</td></tr>
<tr><td>Context loss, 2D cylinder-slice fallback and plain-HTML rescue</td><td>Not verified in Chromium yet</td><td>Falls back to 5-argument <code>drawElementImage()</code> cylinder slices when WebGL 2 <code>texElementSubImage2D()</code> is absent, and moves <code>#pack-label</code> into <code>.plain-host</code> when HTML-in-canvas is missing or the context is lost. Live check 6 runs <code>stillDrawn()</code> on a plain copy of the visible canvas.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>captureElementImage()</code> snapshots cannot be drawn onto a different canvas in Chromium ("The source was captured from a different canvas", recorded in <code>findings/flutter-dom.md</code>). In WebGL 2 mode, reading the already-uploaded flat label texture through a one-shot framebuffer <code>gl.readPixels()</code> on user tap avoids both cross-canvas rejection and extra drawable canvases, while keeping frame loops free of readbacks.</li>
<li>A 720×360 drawable label can overflow a 412 px viewport if left in plain HTML flow or if its stage isn't clipped. The stage keeps <code>overflow: hidden</code> in canvas mode, caps the canvas backing store below 3.6 megapixels, and switches <code>#pack-label</code> to <code>width: 100%; height: auto</code> with a single-column stack below 620 px in <code>.plain-host</code> fallback mode.</li>
<li>On a phone with no pointer hover, dragging over the tin to spin it competes with tapping inputs on the label. Adding a <code>Spin object</code> mode toggle beside <code>Interact with label</code>, pausing auto-orbit while a label field has focus, and setting <code>overflow-anchor: none</code> on the canvas keeps touch orbit and curved editing out of each other's way.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /pack-3d/</code> and <code>node tools/draw-size/audit.mjs /pack-3d/</code>): run both to check layout stability, zero timed readbacks, <code>openSnapshots === 0</code>, backing-store sizing at 412 px and DPR 2.625, and live check pass counts.</li>
<li>Chrome 159 on Android at 412 px wide by touch: spinning the coffee tin and vinyl sleeve, tapping the <code>&lt;input&gt;</code> fields, <code>&lt;select&gt;</code>, colour swatches and tasting-note checkboxes directly on the curved surface, unrolling to the flat print net, and downloading the exported PNG.</li>
<li>Exact FBO readback orientation (<code>UNPACK_FLIP_Y_WEBGL = false</code> with <code>gl.texElementSubImage2D()</code> vs <code>gl.readPixels()</code> row 0) in Chromium 157 and Chrome 159 on Android: confirm the exported PNG is right-side up rather than vertically inverted.</li></ul>
<p><a href="https://html-in-canvas.page/pack-3d/">Open Curved 3D packaging customiser with live DOM labels</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Two-sided 3D hardcover book with live HTML pages</title>
<link>https://html-in-canvas.page/page-book/</link>
<guid isPermaLink="true">https://html-in-canvas.page/page-book/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL</category>
<category>page-curl</category>
<category>ElementGL</category>
<category>updateElementGeometry</category>
<category>3D</category>
<description>Six live HTML pages bound as a hardcover book in one WebGL 2 canvas. Drag a corner to curl both the front and the mirrored back of a leaf over the spine, while checkboxes, inputs, notes and text selection keep working on the open spread.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a multi-page book curl both the front and back of a live HTML leaf across a shaded spine in WebGL while links, checkboxes, notes and text selection keep working on the open spread?</p>
<p><strong>Short answer:</strong> Built with one <code>ElementGL</code> WebGL 2 context, a 28 by 18 cylindrical curl mesh and a 2D folded-slice fallback. Live browser measurements on Chromium 157 and Chrome 159 on Android are not verified yet: press Run on the live checks below to test your browser.</p>
<p>I wanted to know if one WebGL 2 canvas could curl both sides of a live HTML leaf across a shaded book spine, while links, checkboxes, notes and text selection still work on the open spread. Drag any outer page corner to turn a leaf, hold a turn mid-air with the slider, or drag the silk ribbon in the gutter.</p>
<h3>How it works</h3>
<ul>
<li>All six pages live inside one <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> as direct <code>drawable</code> children: cover (page 1), field notes and checklist (pages 2 and 3), compass plate and margin notes (pages 4 and 5), and colophon (page 6). They form three physical two-sided leaves: 1/2, 3/4 and 5/6.</li>
<li>I opened one WebGL 2 context with <code>new ElementGL(canvas, …)</code> from <code>/lib/element-gl.js</code> and compiled two shader programs on <code>stage.gl</code>: a flat book shader for the hardcover boards, page stack, ribbon and stationary spread (with spine-gutter ambient occlusion and a soft cast shadow from the curling leaf), and a cylindrical curl shader for the moving leaf.</li>
<li>The cylindrical geometry follows W. David MacDonald and Calin-Andrei Burloiu's rolling-cylinder model, adapted so the spine edge stays pinned to <code>x = 0</code>. Grabbing a top or bottom corner tilts the cylinder axis during the first half of the turn and straightens it back toward the spine as the leaf lands. This builds on the single-corner HTML page-peel shader in <a href="https://html-in-canvas.page/view-source/">/view-source/</a> and classic page-curl UIs such as Apple Books and Turn.js.</li>
<li>The moving leaf is a 28 by 18 triangle mesh. Its fragment shader checks <code>gl_FrontFacing</code> (adjusted when turning backward from left to right) to sample the front HTML texture on the near face and the back HTML texture with <code>1.0 - vUv.x</code> on the curled underside. When the leaf lands flat on the left, text on the back page reads left to right.</li>
<li>On every settled spread, the script calls <code>canvas.updateElementGeometry()</code> with the flat pixel rectangle of each visible page, toggles <code>dataset.hitTick</code> to clear Chromium's hit-test cache, and marks hidden pages <code>inert</code> with <code>pointer-events: none</code> while leaving their geometry inside the canvas so Chromium keeps their pictures painted for the next curl.</li>
<li>Below 580 CSS pixels wide (such as a 412 px Android phone), the book switches to a single-page layout with the spine on the left edge, keeping the backing store below 4 megapixels and touch targets large.</li>
<li>If WebGL 2 or <code>texElementSubImage2D()</code> is missing, the book draws a 2D folded-slice spread with 5-argument and 9-argument <code>drawElementImage()</code>. If HTML-in-canvas isn't available or <code>webglcontextlost</code> fires, the six pages move into plain HTML until <code>webglcontextrestored</code> brings the canvas back.</li>
</ul>
<h3>Findings</h3>
<p>Live browser runs in Chromium 157 and Chrome 159 on Android are not verified yet. Press "Run these 7 checks" above to measure your browser.</p>
<p>On this device: turn a page or drag the curl slider to record canvas size, paint count and active route here.</p>
<ul>
<li><strong>Not verified yet:</strong> real rendering, two-sided texture uploads, back-page mirroring, <code>updateElementGeometry()</code> hit testing, 2D folded-slice fallback and frame rate in Chromium 157 and Chrome 159 on Android (412 px wide, scale 2.625).</li>
<li><strong>Design limit while held mid-curl:</strong> <code>updateElementGeometry()</code> takes one flat matrix per element, not a curved mesh. Controls stay interactive on the settled spread (and on the stationary flat side), while the curved paper itself isn't hit-tested along the cylinder.</li>
<li><strong>Corner margins:</strong> four 68 by 68 px corner grab zones sit above the canvas with <code>touch-action: none</code> so corner drags don't scroll the page on touch screens. Page padding keeps buttons, inputs and text away from those four corners.</li>
<li><strong>Credits:</strong> builds on <a href="https://html-in-canvas.page/view-source/">/view-source/</a> for the single-corner HTML page-peel shader, Apple Books and Turn.js for page-curl interaction, and W. David MacDonald and Calin-Andrei Burloiu for the cylindrical page-curl geometry.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/page-book.md">findings/page-book.md</a> in the repository.</p>
<p>Results here are <code>not verified</code> on 2026-11-22. The page has passed static graphics (<code>npm run check:gfx</code>) and writing (<code>node tools/writing/check.mjs --strict</code>) checks, and has not yet been run in C157 (headless Chromium 157) or A159 (Chrome 159 on Android, 412 px wide).</p>
<h3>What was built</h3>
<p>One <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> holding six live <code>drawable</code> HTML pages bound as three two-sided leaves (pages 1/2, 3/4 and 5/6):</p>
<ul><li>Page 1 (front cover): hardcover title cartouche, live bookmark colour <code>&lt;select&gt;</code> and editable Ex Libris <code>&lt;input&gt;</code>.</li>
<li>Pages 2 and 3 (spread 1, field notes): selectable serif prose, a clickable footnote <code>&lt;button&gt;</code> toggling an inline <code>&lt;aside&gt;</code>, and a five-item <code>&lt;input type="checkbox"&gt;</code> list with a live <code>&lt;output&gt;</code> tally.</li>
<li>Pages 4 and 5 (spread 2, sketches and notes): an inline SVG compass rose driven by an <code>&lt;input type="range"&gt;</code> scale slider, and a ruled <code>&lt;textarea&gt;</code> margin notebook with live word and character counts.</li>
<li>Page 6 (colophon): plain credits, owner line from page 1, a reading-progress <code>&lt;output&gt;</code>, and a "Jump to cover" <code>&lt;button&gt;</code>.</li></ul>
<p>Rendering uses one WebGL 2 context created via <code>new ElementGL(canvas, …)</code> from <code>/lib/element-gl.js</code> with two shader programs compiled on <code>stage.gl</code>: a flat book shader (hardcover boards, page-block edges, marbled endpapers, silk ribbon, spine-gutter ambient occlusion and cast leaf shadow) and a 28 by 18 cylindrical page-curl mesh shader that selects the front HTML texture on <code>gl_FrontFacing</code> and the horizontally mirrored back HTML texture (<code>1.0 - vUv.x</code>) on the curled underside. When WebGL 2 or <code>texElementSubImage2D()</code> isn't available, the page falls back to a 2D folded-slice spread drawn with 5-argument and 9-argument <code>drawElementImage()</code>. When HTML-in-canvas isn't available or <code>webglcontextlost</code> fires, the six pages move into plain HTML until <code>webglcontextrestored</code> recovers the context.</p>
<p>Credits: this experiment builds on <code>/view-source/</code> on this site for the single-corner HTML page-peel shader, classic page-curl UIs such as Apple Books and Turn.js, and the cylindrical page-curl geometry described by W. David MacDonald and Calin-Andrei Burloiu.</p>
<h3>Results</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Do two live HTML textures upload to one <code>ElementGL</code> WebGL 2 context?</td><td>not verified</td><td>Check 1 uploads front and back <code>drawable</code> children through <code>stage.upload()</code> on an isolated fixture.</td></tr>
<tr><td>Does the 28 by 18 cylindrical mesh show front HTML at <code>t = 0</code> and back HTML at <code>t = 1</code>?</td><td>not verified</td><td>Check 2 renders <code>t = 0</code> and <code>t = 1</code> and probes one pixel on each side of the spine with <code>readPixels()</code>.</td></tr>
<tr><td>Does a mid-curl leaf draw both live front and back HTML in one pass (<code>t = 0.62</code>)?</td><td>not verified</td><td>Check 3 probes near the spine (front) and on the turned flap past the crest (back) in one draw call.</td></tr>
<tr><td>Does the back HTML page read left to right when turned onto the left spread?</td><td>not verified</td><td>Check 4 uses a green-left, amber-right back texture and verifies orientation at <code>t = 1</code>.</td></tr>
<tr><td>Do <code>updateElementGeometry()</code>, <code>inert</code> and <code>dataset.hitTick</code> route pointer hits to the open spread only?</td><td>not verified</td><td>Check 5 switches two overlapping drawable pages and checks <code>document.elementFromPoint()</code>.</td></tr>
<tr><td>Does the 2D folded-slice fallback draw both 5-argument and 9-argument <code>drawElementImage()</code>?</td><td>not verified</td><td>Check 6 draws a flat page and a slice, then copies to a plain <code>willReadFrequently: true</code> 2D canvas to inspect pixels.</td></tr>
<tr><td>Does <code>webglcontextlost</code> fall back to plain HTML and <code>webglcontextrestored</code> recover?</td><td>not verified</td><td>Check 7 dispatches synthetic cancelable <code>webglcontextlost</code> and <code>webglcontextrestored</code> events without calling <code>loseContext()</code>.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Keeping hidden pages painted for the next curl: moving hidden pages' hit boxes far outside the canvas can let Chromium skip rasterising their pictures until they return. The script leaves hidden pages' <code>canvasTransform</code> inside the canvas while setting <code>inert = true</code> and <code>pointer-events: none</code> so clicks and Tab focus stay on the open spread.</li>
<li>Spine pinning under diagonal corner drags: a naive tilted cylinder starts wrapping the bound spine edge once the roll line crosses <code>x = 0</code>. Pinning <code>s_c &gt;= (pageH / 2) * |sin(alpha)|</code> and easing <code>alpha</code> back to zero as <code>t</code> approaches 1 keeps <code>u = 0</code> fixed along the spine for every turn angle.</li>
<li>Backing store budget on HiDPI screens: <code>syncCanvasSize()</code> caps the backing store at 3.8 megapixels so wide screens and 2.625 scale Android phones stay under the 4 MP limit.</li></ul>
<h3>Not verified</h3>
<ul><li>C157: all seven live checks, <code>npm run check:jank -- /page-book/</code>, <code>node tools/draw-size/audit.mjs /page-book/</code>, and Playwright corner-drag and ribbon-drag interaction tests.</li>
<li>A159 (Chrome 159 on Android, 412 px wide, scale 2.625): single-page portrait curl, touch corner drag, touch text selection, on-screen keyboard inside the Ex Libris <code>&lt;input&gt;</code> and margin <code>&lt;textarea&gt;</code>, frame rate during drag, and canvas memory stability.</li></ul>
<h3>Open ideas</h3>
<ul><li>Add a subtle translucent page-bleed option showing faint reverse-side ink through thin paper stock.</li>
<li>Project pointer coordinates through the inverse cylinder mapping while a leaf is held mid-curl so controls on a partially curled page could respond before settling.</li></ul>
<p><a href="https://html-in-canvas.page/page-book/">Open Two-sided 3D hardcover book with live HTML pages</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>3D portal test chamber with live HTML consoles and FBO sightlines</title>
<link>https://html-in-canvas.page/portal-room/</link>
<guid isPermaLink="true">https://html-in-canvas.page/portal-room/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>webgl2</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>framebuffer</category>
<description>A 3D test chamber in WebGL 2 with live HTML wall controls, a Companion Cube and two portals backed by off-screen framebuffer cameras. Orbit the room, shoot portals onto any wall and launch the cube from Blue out of Orange.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a single WebGL 2 canvas render a 3D test chamber with live interactive HTML control panels and a live-HTML Companion Cube, shoot Blue and Orange portals onto walls, render a real secondary-camera portal view into an FBO so you see the live HTML console through the portal, and launch the cube from Blue out of Orange?</p>
<p>
I wanted to find out if a single WebGL 2 canvas could render a 3D test chamber with live HTML wall controls and a Companion Cube, shoot Blue and Orange portals onto any wall, draw a secondary portal camera into an off-screen framebuffer so you see the live HTML console through the portal, and launch the cube out of Orange. The portal-camera render-to-texture design and test chamber aesthetic come from Valve's <em>Portal</em> (2007), while the projective <code>updateElementGeometry()</code> hit testing and split-view ideas build on <a href="https://html-in-canvas.page/three-form/"><code>/three-form/</code></a> and <a href="https://html-in-canvas.page/portal-split/"><code>/portal-split/</code></a> on this site.
</p>
<h3>How it works</h3>
<p>
Everything in the chamber draws on one WebGL 2 context created with <code>new ElementGL(canvas, ...)</code> from <code>/lib/element-gl.js</code>. Inside <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> sit three live HTML children: the right-wall control console (<code>#chamber-console</code>), the back-wall lightbox sign (<code>#chamber-sign</code>) and the Companion Cube face (<code>#cube-face</code>). Whenever you edit the chamber code, pick a lighting theme or launch the cube, Chromium fires a <code>paint</code> event and I re-upload the changed elements with <code>gl.texElementSubImage2D()</code> plus mipmaps.
</p>
<p>
Before drawing the main view, I render two 512×512 off-screen colour-and-depth framebuffers on the same <code>stage.gl</code> context: one for what you see looking into Blue (out of Orange) and one for looking into Orange (out of Blue). Each portal defines an orthonormal frame <code>M</code> on its wall. The virtual camera for Portal A looking out of Portal B is <code>M_B * R_180 * inv(M_A) * M_cam</code>, where <code>R_180 = diag(-1, 1, -1, 1)</code> turns the inward ray around without flipping left and right (its determinant is +1, so text on the console stays readable through the portal). A fragment clip plane discards the exit wall behind Portal B, and in the main pass the elliptical portal surface samples the FBO at screen-space coordinates <code>(ndc.xy * 0.5 + 0.5)</code>. Because <code>VP_virt * T(X) = VP_main * X</code>, parallax lines up at every orbit angle.
</p>
<p>
To keep the right-wall console and back-wall sign clickable in 3D, I project each quad's element CSS coordinates through the main view-projection matrix into canvas CSS pixels, scale by <code>geometryUnit()</code> from <code>/lib/surface.js</code> for HiDPI alignment, pass the 4×4 projective <code>DOMMatrix</code> to <code>canvas.updateElementGeometry()</code> and toggle <code>dataset.hitTick</code> whenever the matrix moves. While you're in Shoot Blue or Shoot Orange mode, those hit boxes move off-canvas so a wall shot won't press a console button by mistake. If WebGL 2 <code>texElementSubImage2D()</code> isn't available, the page falls back to a 2D room view drawn with 5-argument <code>drawElementImage()</code> calls; if HTML-in-canvas is missing or the context is lost, all three elements move into plain HTML below the hidden canvas.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Credit and prior art.</strong> The portal-camera render-to-texture technique and test chamber aesthetic come from Valve's <em>Portal</em> (2007). Projective <code>updateElementGeometry()</code> hit testing and split-view portal concepts build on <a href="https://html-in-canvas.page/three-form/"><code>/three-form/</code></a> and <a href="https://html-in-canvas.page/portal-split/"><code>/portal-split/</code></a> on this site.</li>
<li><strong>Screen-space FBO projection matches live HTML textures with zero distortion.</strong> Rendering the virtual camera with the main projection matrix into a 512×512 FBO and sampling at <code>ndc.xy * 0.5 + 0.5</code> lets you read and watch live edits to <code>#chamber-console</code> through the Blue Portal as you orbit, with no extra WebGL contexts.</li>
<li><strong>A 180-degree Y rotation keeps text readable through the portal.</strong> Using <code>R_180 = diag(-1, 1, -1, 1)</code> has determinant +1, so the portal view rotates into the exit wall's frame without mirroring letters backwards.</li>
<li><strong>Fragment exit-plane clipping avoids oblique-frustum depth issues.</strong> Discarding fragments where <code>dot(worldPos - B.pos, B.normal) &lt; -0.005</code> cleanly hides the wall behind the exit portal on any wall, floor or ceiling, and drawing opaque vortices inside the FBO pass avoids WebGL 2 texture feedback loops.</li>
<li><strong>Caching <code>geometryUnit()</code> per canvas resize prevents layout thrashing.</strong> Calling <code>geometryUnit()</code> once when the canvas size changes and reusing that factor for both <code>#chamber-console</code> and <code>#chamber-sign</code> keeps HiDPI hit boxes lined up without calling <code>getBoundingClientRect()</code> every frame.</li>
<li><strong>Browser verification status.</strong> Source checks (<code>npm run check:gfx</code> and strict writing checks) pass locally; live execution in headless Chromium 157 and Chrome on Android is not verified yet (see <code>findings/portal-room.md</code>).</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/portal-room.md">findings/portal-room.md</a> in the repository.</p>
<p>Built on 2026-11-22. Source checked locally with <code>npm run check:gfx</code> and <code>node tools/writing/check.mjs --strict</code>. All 6 live checks passed in headless <code>Chrome/160.0.8177.0</code> with 0 console errors; interactive DPR=2 clicks on <code>#chamber-console</code> (<code>#con-swap</code>, <code>#con-launch</code>, <code>#con-code</code>) verified after switching from <code>Shoot Blue portal</code> back to <code>Orbit / Interact</code> and via <code>Console close-up</code>. Chrome for Android (A159) and <code>check:jank</code> are <strong>not verified</strong> yet.</p>
<p>The question: can a single WebGL 2 canvas render a 3D test chamber with live interactive HTML control panels and a live-HTML Companion Cube, shoot Blue and Orange portals onto walls, render a real secondary-camera portal view into an FBO so you see the live HTML console through the portal, and launch the cube from Blue out of Orange?</p>
<p>Prior art credited on the page: Valve's <em>Portal</em> (2007) for the portal-camera render-to-texture concept and test chamber aesthetic, plus <code>/three-form/</code> (projective <code>updateElementGeometry()</code> hit testing on 3D quads) and <code>/portal-split/</code> on this site.</p>
<table><thead><tr><th>Experiment</th><th>Status</th><th>Notes</th></tr></thead><tbody><tr><td>Single <code>ElementGL</code> WebGL 2 context uploading three live <code>drawable</code> HTML children (<code>#chamber-console</code>, <code>#chamber-sign</code>, <code>#cube-face</code>)</td><td>measured (Chrome/160.0.8177.0, 2026-11-22)</td><td>Live check 1 verified multi-element upload (<code>80×80</code> blue and orange panels) on one <code>ElementGL</code> context; all three chamber elements upload cleanly with mipmaps on <code>paint</code>.</td></tr>
<tr><td>Secondary-camera portal render into dual 512×512 colour+depth FBOs on <code>stage.gl</code></td><td>measured (Chrome/160.0.8177.0, 2026-11-22)</td><td>Live check 2 verified <code>128×128</code> FBO round-trip pixels (<code>rgba(236,94,154,255)</code>); live check 3 verified <code>det=1.000</code> and <code>NDC error=4.7e-8</code>. Skipping the exit portal in its own FBO pass and using <code>DEPTH_COMPONENT24</code> eliminated exit-plane occlusion and z-fighting.</td></tr>
<tr><td>Projective 3D <code>updateElementGeometry()</code> hit testing scaled with <code>geometryUnit()</code> + <code>dataset.hitTick</code></td><td>measured (Chrome/160.0.8177.0, 2026-11-22)</td><td>Live check 4 hit button at <code>(120.0, 75.0)</code> CSS px; DPR=1 and DPR=2 real mouse clicks hit <code>#con-swap</code>, <code>#con-launch</code> and <code>#con-code</code>. Switching to <code>Console close-up</code> now auto-returns to <code>Orbit / Interact</code>, <code>setMode()</code> toggles <code>inert</code> and clears cached geometry keys, <code>cachedGeometryUnit()</code> invalidates <code>consoleEl</code>'s cached key after probing, and <code>#cube-face</code> is parked off-stage.</td></tr>
<tr><td>Parabolic Companion Cube launch from Blue Portal out of Orange Portal</td><td>Not verified in Chromium yet</td><td>Clicking the cube, the wall console button or the toolbar Launch button arcs the cube into Blue, increments <code>#sign-count</code> and <code>#cube-count</code> at portal transit (raising <code>paint</code>), flashes both portals and arcs the cube out of Orange back onto the floor pad. Live check 5 steps the trajectory and verifies DOM counter mutation raises <code>paint</code>.</td></tr>
<tr><td>Wall-shooting portal placement and layout presets (<code>Look at console through Blue</code>, <code>Opposite walls</code>, <code>Floor drop</code>)</td><td>Not verified in Chromium yet</td><td>Raycasts clicks against all six chamber planes in Shoot Blue / Shoot Orange mode, clamps the ellipse inside wall margins and animates a scale-open pop; <code>Portal view (FBO)</code> checkbox toggles live FBO sightlines against opaque energy vortices.</td></tr>
<tr><td>2D 5-argument <code>drawElementImage()</code> fallback and plain HTML rescue on context loss</td><td>Not verified in Chromium yet</td><td>Falls back to a 2D room schematic with 5-argument <code>drawElementImage()</code> calls when WebGL 2 <code>texElementSubImage2D()</code> is absent, and moves <code>#chamber-console</code>, <code>#chamber-sign</code> and <code>#cube-face</code> into <code>.plain-host</code> when HTML-in-canvas is missing or WebGL context stays lost. Live check 6 verifies 5-arg 2D fallback and <code>window.__gfx?.retire()</code> cleanup.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A naive portal reflection across the exit plane has determinant -1, which flips HTML console text backwards when read through the portal. Using a 180-degree rotation around the portal's local up axis (<code>R_180 = diag(-1, 1, -1, 1)</code>) keeps determinant +1 so text on <code>#chamber-console</code> stays readable through Blue Portal.</li>
<li>Binding an FBO's colour texture as a sampler while rendering into that same FBO triggers a WebGL 2 feedback loop warning and undefined reads. Drawing portals as opaque energy vortices inside the FBO pass (<code>drawPortalsAsVortex = true</code>) and unbinding <code>TEXTURE_2D</code> before switching framebuffers keeps every draw clean.</li>
<li>Calling <code>geometryUnit()</code> separately for <code>#chamber-console</code> (360 px) and <code>#chamber-sign</code> (260 px) on every frame would miss <code>surface.js</code>'s <code>WeakMap</code> cache (keyed by canvas plus element width) and force <code>getBoundingClientRect()</code> layout reads per frame. Caching <code>geometryUnit()</code> per canvas size and reusing the factor for both panels avoids layout thrashing while preserving HiDPI hit-box scaling.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /portal-room/</code> and <code>node tools/draw-size/audit.mjs /portal-room/</code>): run both to confirm zero layout shift, zero timed readbacks, backing-store sizing under 4 MP at 412 px and DPR 2.625, and live check results.</li>
<li>Chrome 159 on Android at 412 px wide by touch: orbiting the chamber, tapping the right-wall <code>#chamber-console</code> buttons, <code>&lt;select&gt;</code> and <code>&lt;input&gt;</code> in <code>Console close-up</code> and <code>Portal sightline</code> views, shooting Blue and Orange portals onto walls and floor, and verifying FBO sightlines update live when typing into <code>#con-code</code>.</li>
<li>Frame rate and visual alignment of the 512×512 FBO portal texture across different aspect ratios (16:10 desktop vs 4:5 phone) on real GPU hardware.</li></ul>
<p><a href="https://html-in-canvas.page/portal-room/">Open 3D portal test chamber with live HTML consoles and FBO sightlines</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Thinking with portals: split live HTML across Blue and Orange portals</title>
<link>https://html-in-canvas.page/portal-split/</link>
<guid isPermaLink="true">https://html-in-canvas.page/portal-split/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>clip</category>
<category>hit testing</category>
<category>physics</category>
<category>forms</category>
<category>portals</category>
<description>Drag or fling live HTML form cards halfway through a Blue portal on one 2D canvas and watch them emerge out of an angled Orange portal with momentum preserved and working controls on both halves.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can one live interactive HTML element pass halfway through a Blue portal and emerge simultaneously out of an angled Orange portal on a 2D canvas with momentum preserved and working controls on both halves?</p>
<p><strong>Short answer:</strong> Not verified in Chromium yet. Six isolated live checks test simultaneous split-clip drawing from one element, angled exit rotation, last-draw-wins hit-box routing, momentum vector rotation, live DOM repainting on both halves and context survival on your device.</p>
<p>
Inspired by Valve's <em>Portal</em> (2007) and building on <a href="https://html-in-canvas.page/portal/">/portal/</a> and <a href="https://html-in-canvas.page/dom-pinball/">/dom-pinball/</a>, I wanted to know if one live HTML card can sit halfway through a Blue portal while its other half sticks out of an angled Orange portal on one 2D canvas, keeping its momentum and working controls on both sides. Drag either card by its top bar, drag or rotate the portals, or tap a preset below.
</p>
<h3>How it works</h3>
<p>
Both cards live inside one <code>&lt;canvas id="portal-canvas" content="drawable" layoutsubtree&gt;</code>.
Each portal has a centre position, a half-length and a unit normal vector pointing into the chamber.
When a card's oriented bounding box straddles the Blue portal plane, I don't clone the DOM node.
Instead, the paint pass draws the same element twice in one frame with five-argument <code>drawElementImage(el, -w / 2, -h / 2, w, h)</code>.
</p>
<p>
Pass A calls <code>ctx.clip()</code> on the half-plane in front of the entry portal and draws the card at its entry pose.
Pass B computes the rigid portal transform from entry to exit: it translates by <code>-entry</code>, rotates by <code>exitNormal - entryNormal + Math.PI</code>, applies the optional exit scale, translates to <code>exit</code>, clips to the half-plane in front of the exit portal, and draws the same element again.
Because the two clipped half-planes meet along the exact portal line, the card slices across the two angled portals with no gap and no overlap.
</p>
<p>
One element in HTML-in-canvas only has one hit-test region at a time (a limit first seen on <a href="https://html-in-canvas.page/portal/">/portal/</a>).
On a 2D canvas, the last <code>drawElementImage()</code> call for an element sets that hit box.
So I track the pointer on <code>pointermove</code> and <code>pointerdown</code>, check which half is under or nearer the pointer, and draw that half second while toggling a <code>data-hit-tick</code> attribute to clear Chromium's hit-test cache.
Portal sightline previews are drawn before the main elements so they never steal hit testing from the cards.
</p>
<p>
When a moving card's centre crosses behind the entry portal plane, its position, angle and velocity swap onto the exit portal using Valve's <em>Portal</em> momentum rule ("speedy thing goes in, speedy thing comes out"): speed stays the same while the velocity vector rotates by <code>exitNormal - entryNormal + Math.PI</code>.
Unticking <code>Preserve momentum</code> inside the live card cuts exit speed to 35%, and changing <code>Cube mode</code> inside the second tile changes its bounce and gravity weight directly.
The loop pauses off screen via <code>IntersectionObserver</code>, respects <code>prefers-reduced-motion: reduce</code>, and moves both cards into plain HTML if <code>contextlost</code> fires.
</p>
<h3>Findings</h3>
<p>
Not verified in Chromium or on an Android phone yet.
I built this experiment on 2026-11-22 crediting Valve's <em>Portal</em> (2007) for the Blue and Orange portal transform and momentum conservation rule, <a href="https://html-in-canvas.page/portal/">/portal/</a> for double-drawing one element with pointer-tracked hit boxes, and <a href="https://html-in-canvas.page/dom-pinball/">/dom-pinball/</a> for running live HTML form controls inside a 2D physics loop.
</p>
<ul>
<li><b>One element only has one hit box, so draw order decides which half you can click.</b> Calling <code>drawElementImage()</code> twice in one frame paints both clipped halves, and the second call sets the hit-test region. Drawing the half nearest the pointer second (and toggling <code>data-hit-tick</code> when that half flips) lets you click the button sticking out of Blue and type into the input sticking out of Orange without cloning the element. Check 3 tests this directly with <code>elementFromPoint()</code>.</li>
<li><b>Half-plane <code>ctx.clip()</code> splits live form controls cleanly across arbitrary exit angles.</b> Because the exit pass applies <code>exitNormal - entryNormal + Math.PI</code> before <code>drawElementImage()</code>, the same DOM element can enter horizontally on one wall and emerge rotated 90 degrees or upside down from another wall. Checks 1 and 2 verify both halves' pixels on a plain copy canvas.</li>
<li><b>Sightline previews must paint before the real elements.</b> Calling <code>drawElementImage()</code> inside a portal's elliptical sightline preview after the cards would hand the element's hit box to the tiny preview. Drawing sightlines behind the cards keeps the final hit box on the active split half.</li>
<li><b>Zero-hover touch taps on the inactive half rely on synchronous retargeting.</b> On a phone there is no <code>pointermove</code> before a tap, so capture-phase <code>pointerdown</code> flips the active half and redraws immediately (falling back to <code>requestPaint()</code> if the browser rejects an out-of-paint draw). Whether a single tap activates a button on the previously inactive half without a second tap needs testing on Chrome for Android.</li>
<li><b>Not verified:</b> Chromium 157 headless check results, Android 412 px touch dragging of cards and portal knobs, single-tap hit-box switching on the inactive half without hover, keyboard caret rendering when an <code>&lt;input&gt;</code> is cut directly across a portal line, and frame rate during infinite-fall loops with sightlines on.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/portal-split.md">findings/portal-split.md</a> in the repository.</p>
<p>Built on 2026-11-22. Live browser behaviour is not verified in Chromium 157 (C157) or Chrome on Android (A159) yet; static checks (<code>check:gfx</code> and <code>check:writing</code>) passed locally, and the page ships six isolated live checks to measure each behaviour in your browser.</p>
<p>This experiment takes its Blue and Orange portal mechanic and momentum conservation rule ("speedy thing goes in, speedy thing comes out") from Valve's <em>Portal</em> (2007), and builds on <code>/portal/</code> (<code>&lt;dom-portal&gt;</code>, double-drawing one element with pointer-tracked hit boxes) and <code>/dom-pinball/</code> (live HTML form controls inside a 2D canvas physics loop).</p>
<p>The question: can one live interactive HTML element pass halfway through a Blue portal and emerge simultaneously out of an angled Orange portal on a 2D canvas with momentum preserved and working controls on both halves?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Simultaneous split-clip drawing of one <code>drawable</code> HTML card across Blue and Orange portals</td><td>not verified</td><td>One element is drawn twice per frame with five-argument <code>drawElementImage()</code> under complementary half-plane <code>ctx.clip()</code> paths (<code>dot(p - portal, normal) &gt;= 0</code>). Live check 1 verifies one DOM node paints its right half at Blue and its left half at Orange in the same frame via a plain <code>drawImage()</code> copy canvas.</td></tr>
<tr><td>Angled exit orientation via rigid portal transform <code>exitNormal - entryNormal + PI</code></td><td>not verified</td><td>Entering a floor portal (<code>-PI/2</code>) and exiting a left-wall portal (<code>0</code>) rotates the emerging half by <code>-90</code> degrees; optional <code>Exit scale</code> (<code>0.6x</code> to <code>1.4x</code>) scales the exit transform around the exit portal. Live check 2 verifies rotated stripe pixels on a plain copy canvas.</td></tr>
<tr><td>Single-hit-box routing across two split halves using draw order</td><td>not verified</td><td>An HTML-in-canvas element has one hit-test region; on a 2D canvas the last <code>drawElementImage()</code> call wins it. Tracking <code>pointermove</code> and <code>pointerdown</code> to draw the half nearest the pointer second and toggling <code>data-hit-tick</code> routes clicks and typing to either half. Live check 3 verifies <code>elementFromPoint()</code> flips between halves when draw order reverses.</td></tr>
<tr><td>Momentum conservation across angled portals and live DOM physics controls</td><td>not verified</td><td>Crossing a portal rotates <code>(vx, vy)</code> by <code>exitNormal - entryNormal + PI</code> while keeping speed unchanged unless <code>Preserve momentum</code> inside the live card is unticked (damping to <code>35%</code>). Changing <code>&lt;select&gt;</code> <code>Cube mode</code> on Tile 02 updates its restitution and gravity scale. Live check 4 verifies velocity rotation and speed conservation across opposite, 90-degree and floor-to-floor pairs.</td></tr>
<tr><td>Live DOM mutations inside a split element repainting both halves</td><td>not verified</td><td>Adding a class or mutating form state inside the one DOM node should raise <code>paint</code> without <code>requestPaint()</code> and update both clipped halves. Live check 5 verifies both entry and exit pixels change after a class mutation.</td></tr>
<tr><td>Sightline previews, reduced motion, off-screen pause and <code>contextlost</code> fallback</td><td>not verified</td><td>Portal sightlines draw before the cards so preview draws never claim an element's hit box. The canvas stays under 4 MP at DPR 2.625, pauses off screen (<code>IntersectionObserver</code>), stops portal swirl under <code>prefers-reduced-motion: reduce</code>, and moves both cards to plain HTML on <code>contextlost</code>. Live check 6 runs <code>stillDrawn()</code> via a plain <code>drawImage()</code> copy.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><strong>Single hit box for one element.</strong> Drawing one element twice in the same 2D paint pass paints pixels in both places, but only the last <code>drawElementImage()</code> call sets the hit box. Drawing the pointer-side half second and toggling <code>data-hit-tick</code> clears Chromium's hit-test cache and lets you interact with controls sticking out of either portal.</li>
<li><strong>Sightline preview draw order.</strong> Because the optional portal-to-portal sightline preview also calls <code>drawElementImage()</code> clipped to the thin oval aperture, drawing sightlines after the main cards would hand the hit box to the tiny preview. Painting sightlines in Layer 1 behind the cards avoids that conflict.</li>
<li><strong>Continuous dragging across a portal plane.</strong> Swapping a card's coordinates the moment its centre crosses <code>d = 0</code> during a pointer drag would jump the drag anchor across the chamber. Letting <code>d</code> go negative while held and swapping once the card fully clears (or on <code>pointerup</code>) keeps dragging continuous without moving any drawn pixels.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in headless Chromium 157 (<code>npm run check:jank -- /portal-split/</code> and <code>node tools/draw-size/audit.mjs /portal-split/</code>).</li>
<li>Chrome on Android (412 px wide, DPR 2.625): dragging the card header bars and portal rotation knobs by touch, plus single-tap activation on the previously inactive split half without a prior hover event.</li>
<li>Text caret and selection rendering when <code>&lt;input id="subject-input"&gt;</code> is sliced directly across a portal boundary while focused.</li>
<li>Frame rate during <code>Infinite fall (floor to ceiling)</code> with <code>Portal sightlines</code> enabled on a phone GPU.</li>
<li>Real <code>contextlost</code> and <code>contextrestored</code> recovery on Android hardware.</li></ul>
<p><a href="https://html-in-canvas.page/portal-split/">Open Thinking with portals: split live HTML across Blue and Orange portals</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>3D relief map with live DOM pins and weather cards</title>
<link>https://html-in-canvas.page/relief-map/</link>
<guid isPermaLink="true">https://html-in-canvas.page/relief-map/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL 2</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>ElementGL</category>
<description>A procedural WebGL 2 relief island with real-time sun hillshading and contour lines, carrying four live HTML weather cards in 3D space. Orbit the map, move the sun, switch between billboard and flat cards, and click or type inside each card.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a procedural WebGL 2 relief terrain map with real-time sun shading anchor live interactive HTML weather and waypoint cards in 3D space so they project, depth-scale, cast shadows on the terrain, and still take clicks and typing?</p>
<p><strong>Short answer:</strong> Built on one ElementGL WebGL 2 context with terrain-conformed ground shadows, back-to-front card sorting and projective updateElementGeometry() hit boxes. Live browser verification is not run yet.</p>
<p>
I wanted to know if a procedural WebGL 2 relief map with real-time sun shading could hold live HTML weather cards in 3D space without breaking clicks or typing.
Drag to orbit the island, pinch or scroll to zoom, sweep the sun azimuth to shift shadows across the ridges, or edit the field note and temperature units directly inside any card.
</p>
<h3>How it works</h3>
<p>
I took the idea from shader-driven relief maps like Mapbox GL and Tangram terrain hillshading, and from Three.js procedural topography experiments, then combined it with the 3D <code>updateElementGeometry()</code> hit-test pattern from <a href="https://html-in-canvas.page/three-form/">/three-form/</a>.
Instead of loading external map tiles or a 3D engine, a deterministic noise function generates a 64 by 64 island heightfield with a central peak, an eastern granite ridge, a western harbour bay and a southern headland.
</p>
<p>
Everything renders on one WebGL 2 context created by <code>new ElementGL(canvas, ...)</code>. On each <code>paint</code> event, the terrain mesh draws first with depth testing on. The vertex shader stores raw height and unscaled slope gradients once in the buffer, so dragging the elevation scale slider updates peaks and surface normals on the GPU without rebuilding geometry.
Next, soft drop-shadow ellipses conformed to the local terrain height and screen-aligned pin stems draw over the slopes, shifting direction as you drag the sun azimuth slider.
</p>
<p>
After restoring <code>ElementGL</code>'s shader program and vertex array object, the four station cards are sorted back-to-front by camera distance and drawn with <code>stage.quad()</code>.
Each card's element-to-canvas projective matrix goes to <code>canvas.updateElementGeometry()</code>, scaled by <code>geometryUnit()</code> for high-DPI screens, and its <code>data-hit-tick</code> attribute toggles whenever the matrix changes to clear Chromium's hit-test cache.
If WebGL 2 HTML-in-canvas isn't available, the page falls back to a 2D isometric relief projection with five-argument <code>drawElementImage()</code>, or to plain HTML cards below the 2D relief canvas when HTML-in-canvas is disabled.
</p>
<h3>Findings</h3>
<ul>
<li>Drawing custom 3D WebGL 2 geometry and live DOM textures inside one <code>ElementGL</code> context works by saving <code>CURRENT_PROGRAM</code> and <code>VERTEX_ARRAY_BINDING</code> after <code>stage.begin()</code>, rendering the terrain, conformed ground shadows and stems on <code>stage.gl</code>, and restoring both bindings before calling <code>stage.quad()</code>. This keeps the page to one WebGL context without modifying <code>element-gl.js</code>.</li>
<li>Sorting cards back-to-front by view-space depth and matching each card's <code>zIndex</code> only when the sort order flips aligns visual occlusion with DOM pointer hit-testing where two cards overlap.</li>
<li>In flat-on-map mode, keeping the camera pitch above 18 degrees keeps the top face of every horizontal card front-facing from all 360 degrees of camera yaw, so the cards stay readable and interactive as you orbit around them.</li>
<li>Credits: terrain hillshading and hypsometric contour bands follow shader-driven relief map techniques from Mapbox GL, Tangram and Three.js procedural topography work; the projective <code>updateElementGeometry()</code> pattern builds on <a href="https://html-in-canvas.page/three-form/">/three-form/</a>.</li>
<li>Not verified yet: live browser runs in headless Chromium 157 and on Chrome 159 for Android (412 px touch orbit, pinch zoom, native <code>&lt;select&gt;</code> picker over a 3D card, and on-screen keyboard typing into a projected <code>&lt;input&gt;</code>). Running the live checks above and testing touch input on a device will verify those paths.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/relief-map.md">findings/relief-map.md</a> in the repository.</p>
<p>Status on 2026-11-22: static checks passed (<code>check:gfx</code>, <code>check:writing --strict</code>, JSON and module parse, deterministic heightfield check in Node). Live browser verification in Chromium 157 and on Android Chrome 159 is not verified yet.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>One <code>ElementGL</code> WebGL 2 context drawing a 3D procedural relief terrain mesh and live <code>drawable</code> HTML weather cards</td><td>not verified</td><td>Implemented by saving <code>CURRENT_PROGRAM</code> and <code>VERTEX_ARRAY_BINDING</code> after <code>stage.begin()</code>, drawing the 64 by 64 relief mesh, terrain-conformed ground shadows and pin stems on <code>stage.gl</code>, and restoring both bindings before <code>stage.quad()</code>. Needs a Chromium 157 run to verify on screen.</td></tr>
<tr><td>Back-to-front depth sorting and <code>zIndex</code> ordering for overlapping 3D weather cards</td><td>not verified</td><td>Cards sort by view-space depth each frame, and <code>style.zIndex</code> updates only when the depth order flips. Covered by an isolated live check on <code>testStage()</code>.</td></tr>
<tr><td>Projective <code>updateElementGeometry()</code> hit boxes with <code>dataset.hitTick</code> cache clearing in billboard and flat-on-map modes</td><td>not verified</td><td>Uses the element-to-canvas projective matrix pattern from <code>/three-form/</code>, scaled by <code>geometryUnit()</code>. Keeping camera pitch above 18 degrees keeps flat-on-map cards front-facing from all 360 degrees of yaw.</td></tr>
<tr><td>Live clicks, <code>&lt;select&gt;</code> unit changes and <code>&lt;input&gt;</code> typing inside projected 3D weather cards</td><td>not verified</td><td>Pointer orbit ignores events targeting interactive controls (<code>button</code>, <code>input</code>, <code>select</code>, <code>label</code>). Needs a live Chromium 157 and Android Chrome 159 run to confirm native pickers and keyboard entry.</td></tr>
<tr><td>2D isometric relief fallback with five-argument <code>drawElementImage()</code> and plain HTML fallback</td><td>not verified</td><td>Falls back to a painter's-algorithm 2D relief canvas with five-argument <code>drawElementImage()</code> when WebGL 2 <code>texElementSubImage2D()</code> is absent, and moves the cards into a plain HTML grid if HTML-in-canvas is disabled or the WebGL context is lost.</td></tr>
<tr><td>Deterministic procedural heightfield and sun azimuth hillshading with no external tiles</td><td>measured (Node, 2026-11-22)</td><td>Evaluated the heightfield and gradient functions in Node: summit <code>0.8813</code>, ridge <code>0.4750</code>, cove <code>0.1479</code>, harbour <code>0.0198</code>. Opposing sun azimuths (<code>60°</code> vs <code>240°</code>) shift slope dot product from <code>0.6118</code> to <code>0.3768</code>.</td></tr></tbody></table>
<h3>Credits and prior work</h3>
<ul><li>Terrain hillshading, hypsometric elevation bands and anti-aliased contour lines follow shader-driven relief map techniques used in Mapbox GL, Tangram terrain hillshading and Three.js procedural topography experiments.</li>
<li>The projective <code>updateElementGeometry()</code> hit-test matrix builds on <code>/three-form/</code> on this site.</li></ul>
<h3>Things that bit</h3>
<ul><li><code>ElementGL</code> keeps its quad shader <code>#program</code> and <code>#vao</code> as private fields, so drawing a custom terrain mesh on <code>stage.gl</code> replaces the active program and VAO before <code>stage.quad()</code> runs. Reading <code>gl.getParameter(gl.CURRENT_PROGRAM)</code> and <code>gl.getParameter(gl.VERTEX_ARRAY_BINDING)</code> once after <code>stage.begin()</code> (and clearing the cached handles on <code>webglcontextlost</code> and <code>webglcontextrestored</code>) lets one context draw both the 3D scene and the DOM textures with no edits to <code>public/lib/element-gl.js</code>.</li>
<li>Initial coordinates for West Harbour (<code>-1.36, 0.62</code>) fell inside the carved coastal bay (<code>-0.2249</code>), placing the harbour pin offshore in water. Moving the pin to <code>-1.26, 0.36</code> placed it on the shoreline at <code>0.0198</code> above sea level.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /relief-map/</code> and <code>?autochecks=1</code>): verifying WebGL 2 terrain plus <code>texElementSubImage2D()</code> compositing, all six live checks, zero layout shift, and open snapshot and memory limits.</li>
<li>Chrome 159 on Android (412 px wide, scale 2.625): verifying touch orbit, two-finger pinch zoom, tapping buttons, opening a <code>&lt;select&gt;</code> picker on a projected 3D card, and typing into a field note <code>&lt;input&gt;</code> with the on-screen keyboard.</li>
<li>Context loss and recovery (<code>webglcontextlost</code> and <code>webglcontextrestored</code>) on a phone, confirming the plain HTML fallback appears and the terrain shaders rebuild cleanly when the context returns.</li></ul>
<p><a href="https://html-in-canvas.page/relief-map/">Open 3D relief map with live DOM pins and weather cards</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Temporal display shaders: E-Ink, Playdate crank and Game Boy LCD</title>
<link>https://html-in-canvas.page/retro-display/</link>
<guid isPermaLink="true">https://html-in-canvas.page/retro-display/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL</category>
<category>texElementSubImage2D</category>
<category>feedback</category>
<category>dithering</category>
<category>E-Ink</category>
<category>Playdate</category>
<category>Game Boy</category>
<description>A live scrolling HTML reader drawn through one WebGL 2 canvas with ping-pong feedback framebuffers. Switch between E-Ink Carta partial-refresh ghosting with a full black flash, a 1-bit Playdate screen with a draggable rotary crank, and a 4-shade olive Game Boy DMG-01 LCD with slow pixel persistence.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a WebGL 2 ping-pong feedback shader give live interactive HTML real temporal hardware screen behaviour (E-Ink partial-refresh ghosting and full black flash, 1-bit Playdate crank scrolling, and 4-shade Game Boy DMG persistence) that stateless CSS filters cannot express?</p>
<p><strong>Short answer:</strong> Not verified in a live browser yet. One ElementGL canvas uploads the scrolling reader with texElementSubImage2D(), feeds each frame through two ping-pong RGBA8 framebuffers to keep ghosting and LCD persistence across updates, renders the bezel and Playdate rotary crank in WebGL, and syncs hit testing with updateElementGeometry().</p>
<p>
I wanted to know if a WebGL 2 ping-pong feedback shader could give live interactive HTML the temporal behaviour of hardware screens that stateless CSS filters can't express.
Scroll, type, tick the boxes or press the buttons inside the screen below, then switch between E-Ink Carta partial-refresh ghosting with a full black flash, a 1-bit Playdate LCD driven by a draggable rotary crank, and a 4-shade olive Game Boy DMG-01 LCD with slow pixel persistence.
</p>
<h3>How it works</h3>
<p>
This experiment builds on <a href="https://html-in-canvas.page/canvas-skin/">/canvas-skin/</a> (styling live controls through shaders) and <a href="https://html-in-canvas.page/time-scrubber/">/time-scrubber/</a> (keeping temporal history across frames), and draws directly from three hardware screens: E-Ink Pearl and Carta partial-refresh panels, Panic's Playdate handheld (1-bit Sharp Memory LCD with a physical rotary crank), and Nintendo's Game Boy DMG-01 4-shade passive-matrix LCD.
</p>
<p>
CSS filters and SVG filter chains are stateless: they transform the current frame's pixels and forget every frame before it.
To model real E-Ink ghosting or passive-matrix LCD trails, the renderer has to remember what was on screen on the previous update.
I used one WebGL 2 context created with <code>new ElementGL(canvas, ...)</code> from <code>/lib/element-gl.js</code> and allocated two small RGBA8 ping-pong framebuffers on <code>stage.gl</code>.
</p>
<p>
Each time <code>#rd-screen</code> paints, scrolls or changes, <code>ElementGL.upload()</code> copies its picture into a WebGL texture via <code>gl.texElementSubImage2D()</code>.
Pass 1 runs the feedback shader into the back framebuffer, reading both the live texture and the previous state texture.
In E-Ink mode it deposits lingering dark ghosting in the green channel whenever a dark pixel clears to white, holds that ghost while the panel is idle, and wipes it to zero during the 220 ms black-to-white full refresh waveform.
In Game Boy DMG mode it blends the live luminance toward the previous state with an asymmetric decay factor over a short settling loop, then stops requesting animation frames once the trail settles.
</p>
<p>
Pass 2 draws the entire handheld shell and screen in one quad using <code>ElementGL.quad()</code>: 4x4 ordered Bayer dithering, a 16-level warm paper ramp for E-Ink, razor-sharp 1-bit monochrome (<code>#c7c3b8</code> and <code>#2c2b28</code>) with a pixel grid and SDF rotary crank for Playdate, and the 4-shade olive palette (<code>#9bbc0f</code>, <code>#8bac0f</code>, <code>#306230</code>, <code>#0f380f</code>) with subpixel gaps and cast pixel shadow for Game Boy DMG-01.
After sizing or switching modes, the page calls <code>canvas.updateElementGeometry(screen, { canvasTransform })</code> and increments <code>screen.dataset.hitTick</code> so clicks, focus, typing and scrolling land inside the rendered screen box.
</p>
<p>
If WebGL 2 isn't available, the page falls back to a 2D canvas drawing <code>#rd-screen</code> with 5-argument <code>drawElementImage()</code> and copying into a plain non-drawable <code>willReadFrequently: true</code> scratch canvas for ordered Bayer dithering on each paint.
If the HTML-in-canvas API isn't enabled or the WebGL context is lost, <code>#rd-screen</code> moves out of the canvas so the reader stays usable as plain HTML until the context returns.
</p>
<h3>Findings</h3>
<ul>
<li>Not verified yet in a live browser: none of the checks or visual modes have been run in Chromium 157 or on Chrome 159 for Android yet. Open the page in a browser with HTML-in-canvas enabled and run the live checks above to record measured results.</li>
<li>Credits and inspirations: E-Ink Pearl and Carta partial-refresh waveforms, Panic's Playdate handheld (1-bit Sharp Memory LCD and physical rotary crank), Nintendo's Game Boy DMG-01 4-shade passive-matrix LCD, plus <a href="https://html-in-canvas.page/canvas-skin/">/canvas-skin/</a> and <a href="https://html-in-canvas.page/time-scrubber/">/time-scrubber/</a> on this site.</li>
<li>One <code>ElementGL</code> context is enough for both element uploads and off-screen ping-pong framebuffers. Reusing <code>stage.gl</code> avoids opening a second WebGL context and keeps total GPU memory well under the mobile budget.</li>
<li>Mounting the Playdate crank hit target (<code>#crank-pad</code>) as a sibling element over the right bezel with <code>touch-action: none</code> lets circular touch drags spin <code>#rd-screen.scrollTop</code> without blocking native touch scrolling or text selection inside the screen.</li>
<li>Because E-Ink ghosting only steps when the DOM updates and Game Boy DMG stops its settling loop after trails fade out, the canvas draws zero frames at rest.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/retro-display.md">findings/retro-display.md</a> in the repository.</p>
<p>Not verified in a live browser as of 2026-11-22. None of the checks or visual modes have been run in headless Chromium 157 (C157) or on Chrome 159 for Android (A159) yet. Static checks (<code>npm run check:gfx</code> and <code>tools/writing/check.mjs</code>) passed on 2026-11-22.</p>
<p>Inspired by E-Ink Pearl and Carta partial-refresh panels, Panic's Playdate handheld (1-bit Sharp Memory LCD and physical rotary crank), Nintendo's Game Boy DMG-01 4-shade passive-matrix LCD, plus <code>/canvas-skin/</code> and <code>/time-scrubber/</code> on this site.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Can a WebGL 2 ping-pong feedback shader keep E-Ink partial-refresh ghosting across live DOM updates and clear it with a 220 ms black flash?</td><td>Not verified</td><td>Implemented with two RGBA8 ping-pong framebuffers allocated on <code>ElementGL</code>'s single WebGL 2 context (<code>stage.gl</code>). The green channel accumulates residual dark pigment when a dark DOM pixel clears to light; the 220 ms flash waveform inverts to black, clears to paper white and zeroes the ghost channel.</td></tr>
<tr><td>Can a canvas-rendered Playdate rotary crank drive <code>#rd-screen.scrollTop</code> while live controls inside the screen stay interactive?</td><td>Not verified</td><td>Implemented with an accessible <code>#crank-pad</code> slider overlaid on the right bezel (<code>touch-action: none</code>) using <code>setPointerCapture()</code>, wheel events and keyboard arrows to drive <code>#rd-screen.scrollTop</code>, while <code>canvas.updateElementGeometry()</code> and <code>screen.dataset.hitTick</code> keep hit boxes aligned to the recessed screen rectangle.</td></tr>
<tr><td>Can a 4-shade Game Boy DMG-01 passive-matrix LCD persistence trail run without keeping an idle animation loop alive?</td><td>Not verified</td><td>Implemented with an asymmetric temporal decay factor in the feedback pass and an 850 ms settling timer (<code>dmgSettleUntil</code>) that stops <code>requestAnimationFrame()</code> once trails finish fading out.</td></tr>
<tr><td>Does the page work with one WebGL 2 context and a 2D Bayer fallback?</td><td>Not verified</td><td>Uses one <code>ElementGL</code> context for both element texture uploads (<code>gl.texElementSubImage2D()</code>) and off-screen ping-pong framebuffers. If WebGL 2 is unavailable, a 2D fallback draws with 5-argument <code>drawElementImage()</code> and copies into a plain non-drawable <code>willReadFrequently: true</code> scratch canvas for ordered 4x4 Bayer dithering.</td></tr>
<tr><td>Does <code>webglcontextlost</code> preserve the live reader state?</td><td>Not verified</td><td>On <code>webglcontextlost</code>, <code>#rd-screen</code> moves out of <code>&lt;canvas&gt;</code> into <code>#rd-wrap</code> as plain HTML so typed notes, scroll position, checkboxes and counters stay intact until <code>webglcontextrestored</code> rebuilds the FBOs and moves <code>#rd-screen</code> back.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>ElementGL</code> enables premultiplied alpha blending (<code>gl.enable(gl.BLEND)</code>) when building its context. Writing non-colour state channels (displayed luminance in <code>R</code>, accumulated E-Ink ghosting in <code>G</code>, previous live luminance in <code>B</code>) into the off-screen ping-pong FBO requires <code>gl.disable(gl.BLEND)</code> during Pass 1 and <code>gl.enable(gl.BLEND)</code> again before Pass 2.</li>
<li>Putting <code>touch-action: none</code> on the whole <code>&lt;canvas&gt;</code> would interfere with native vertical touch scrolling inside <code>#rd-screen</code> on a phone. Placing <code>#crank-pad</code> as a sibling overlay restricted to the right-bezel crank bay isolates circular touch drags from screen scrolling and text selection.</li>
<li>Mapping <code>aPos * 2.0 - 1.0</code> in the Pass 1 vertex shader keeps FBO row 0 aligned with <code>texElementSubImage2D()</code> row 0 (top of the DOM element), matching <code>ElementGL.rect()</code> in Pass 2 with no vertical flip.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the 7 live checks in Chromium 157 (C157) and confirming exact readback pixel counts for E-Ink ghosting, full flash clearing, Playdate 1-bit Bayer stippling, Game Boy DMG trail decay and <code>updateElementGeometry()</code> hit testing.</li>
<li>Real touch feel and frame pacing on Chrome 159 for Android (A159) at 412 px wide (device scale 2.625): dragging the Playdate rotary crank by thumb, typing with the on-screen keyboard inside <code>#rd-screen</code>, selecting text inside the recessed screen, and checking total GPU memory with <code>npm run check:jank -- /retro-display/</code>.</li>
<li>Whether scrolling <code>#rd-screen</code> inside <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> raises native <code>paint</code> events on every scroll step on A159, or relies on the page's <code>scroll</code> listener calling <code>canvas.requestPaint()</code>.</li>
<li>Visual legibility of the 4x4 Bayer dithering and 4-shade DMG dot-matrix gaps at pixel scales from <code>1.0x</code> to <code>4.0x</code> on a HiDPI phone screen.</li>
<li>The 2D ordered-Bayer fallback path when WebGL 2 is disabled, and real <code>webglcontextlost</code> / <code>webglcontextrestored</code> recovery under memory pressure on a phone.</li>
<li><code>prefers-reduced-motion: reduce</code> behaviour (instant ghost clear instead of the 220 ms black flash waveform, and suppressed continuous DMG settling).</li>
<li>Screen reader announcements and keyboard navigation for <code>#crank-pad</code> (<code>role="slider"</code>) alongside controls inside <code>#rd-screen</code>.</li></ul>
<p><a href="https://html-in-canvas.page/retro-display/">Open Temporal display shaders: E-Ink, Playdate crank and Game Boy LCD</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Sanitised HTML, cross-shadow selection and Temporal snapshots</title>
<link>https://html-in-canvas.page/sanitized-stream/</link>
<guid isPermaLink="true">https://html-in-canvas.page/sanitized-stream/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>setHTML</category>
<category>Sanitizer</category>
<category>getComposedRanges</category>
<category>Temporal</category>
<category>captureElementImage</category>
<description>Insert untrusted markup into a drawable canvas with Element.setHTML(), trace a selection across a shadow-root canvas with getComposedRanges(), and stamp captureElementImage() frames with Temporal.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Do Element.setHTML(), getSelection().getComposedRanges() and Temporal work alongside a drawable 2D canvas without losing interactivity or leaking snapshots?</p>
<p><strong>Short answer:</strong> Not verified yet in headless Chromium 157 or on Chrome for Android. Open this page and run the live checks to measure all three on your browser.</p>
<p>
I wanted to test three newer browser APIs directly alongside a drawable 2D canvas: inserting untrusted markup with <code>Element.setHTML()</code>, reading a cross-shadow selection with <code>getSelection().getComposedRanges()</code>, and stamping <code>captureElementImage()</code> frames with <code>Temporal</code>.
</p>
<h3>How it works</h3>
<p>
Every canvas on this page uses a 2D context scaled to its backing device pixels via a <code>ResizeObserver</code>. Each <code>ctx.drawElementImage()</code> call passes explicit CSS width and height so elements stay at 1:1 size on high-density screens instead of scaling by <code>devicePixelRatio</code> twice.
</p>
<p>
In the first experiment, <code>Element.setHTML()</code> parses and sanitises untrusted markup directly into the drawable <code>&lt;article&gt;</code> child. A separate inert <code>DOMParser</code> parse of the raw string computes the tag and attribute diff without running scripts or fetching images. For 700 ms after each sanitisation, <code>requestAnimationFrame</code> calls <code>requestPaint()</code> so the scan line sweeps across the newly painted DOM and then stops.
</p>
<p>
In the second experiment, <code>&lt;shadow-sel-box&gt;</code> puts its drawable canvas inside an open shadow root. When <code>selectionchange</code> fires, the page compares <code>getSelection().getRangeAt(0)</code> with <code>getSelection().getComposedRanges({ shadowRoots: [shadow] })</code>. Because a <code>StaticRange</code> has no <code>getClientRects()</code> method and a single live <code>Range</code> can't span a shadow boundary, the script slices the composed range against the shadow root's text nodes to collect line rectangles and paints a ribbon behind the text before calling <code>drawElementImage()</code>.
</p>
<p>
In the third experiment, pressing Capture frame sets a pending flag and requests a paint so <code>captureElementImage()</code> runs right after the latest edit paints. The filmstrip holds at most 4 <code>ElementImage</code> objects; adding a fifth calls <code>close()</code> on the oldest snapshot, and <code>pagehide</code> closes every remaining snapshot. During <code>paint</code>, the filmstrip thumbnails draw first and the live note card draws last, because the last <code>drawElementImage()</code> call for an element determines its hit box.
</p>
<h3>Findings</h3>
<ul>
<li>Not verified yet in headless Chromium 157 or on Chrome for Android: run the live checks on this page to verify <code>Element.setHTML()</code>, <code>getSelection().getComposedRanges()</code>, <code>selection.direction</code> and <code>Temporal.Now</code> alongside <code>drawElementImage()</code> and <code>captureElementImage()</code> in your browser.</li>
<li><code>StaticRange</code> from <code>getComposedRanges()</code> doesn't expose <code>getClientRects()</code>, so painting a canvas highlight across a shadow boundary still requires projecting the composed endpoints onto live <code>Range</code> instances inside each tree.</li>
<li>Drawing captured <code>ElementImage</code> thumbnails before the live editable card on the same canvas keeps clicks and typing aligned with the live controls while avoiding a second canvas context.</li>
<li>Calling <code>close()</code> on every evicted <code>ElementImage</code> and on <code>pagehide</code> caps open snapshots at 4 during normal use and returns open count to 0 when cleared.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/sanitized-stream.md">findings/sanitized-stream.md</a> in the repository.</p>
<p>Created on 2026-11-22. Live browser results are not verified yet in headless Chromium 157 (C157) or on the test phone (A159); the page ships six isolated live checks that measure each API in the visitor's browser.</p>
<table><thead><tr><th>Question</th><th>Status</th><th>Notes</th></tr></thead><tbody><tr><td><code>Element.setHTML()</code> into a <code>drawable</code> 2D canvas child</td><td>not verified</td><td>Inserts untrusted markup (mixing <code>&lt;script&gt;</code>, <code>&lt;img onerror&gt;</code>, <code>&lt;iframe src="javascript:..."&gt;</code>, inline <code>onclick</code>, and safe headings/links/buttons) via <code>el.setHTML()</code> and checks that zero payloads run while the sanitised DOM paints and stays interactive.</td></tr>
<tr><td>Custom <code>Sanitizer</code> options (<code>removeElement</code> / <code>removeElements</code>)</td><td>not verified</td><td>Toggles <code>&lt;b&gt;</code>, <code>&lt;a&gt;</code> and <code>&lt;button&gt;</code> removal through <code>new Sanitizer()</code> (with a <code>SanitizerConfig.removeElements</code> fallback) and computes a live removed vs kept diff against an inert <code>DOMParser</code> parse.</td></tr>
<tr><td><code>getSelection().getComposedRanges({ shadowRoots })</code> across a shadow-root drawable canvas</td><td>not verified</td><td>Compares <code>getRangeAt(0)</code> against <code>getComposedRanges({ shadowRoots: [shadow] })</code> on a passage that crosses into <code>&lt;shadow-sel-box&gt;</code>'s open shadow root and paints a glowing ribbon across the shadow text lines.</td></tr>
<tr><td><code>selection.direction</code> across a shadow boundary</td><td>not verified</td><td>Checks <code>forward</code>, <code>backward</code> and <code>none</code> when extending a selection into or out of the shadow root.</td></tr>
<tr><td><code>Temporal.Now.instant()</code> and <code>Temporal.Now.zonedDateTimeISO()</code> on <code>captureElementImage()</code> snapshots</td><td>not verified</td><td>Stamps up to 4 frozen <code>ElementImage</code> frames in a filmstrip drawn before the live editable note card, measures inter-frame deltas with <code>instant.since(prev)</code>, and calls <code>close()</code> on every evicted snapshot and on <code>pagehide</code>.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>getComposedRanges()</code> returns <code>StaticRange</code> objects, which have no <code>getClientRects()</code> method, and a single live <code>Range</code> cannot span a shadow boundary. Projecting the composed start and end onto per-text-node <code>Range</code> instances inside the shadow root gives accurate line boxes for the canvas ribbon.</li>
<li>Drawing <code>ElementImage</code> filmstrip frames after the live note card moves the hit box away from the live controls. Drawing the frozen thumbnails first and the live card last keeps typing and button presses aligned on a single 2D canvas.</li>
<li>Computing the removed vs kept diff on untrusted input cannot use a live element without risking script execution or image fetches. Parsing the raw string through <code>new DOMParser().parseFromString(raw, 'text/html')</code> keeps the diff inert.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in headless Chromium 157 (<code>npm run check:jank -- --checks /sanitized-stream/</code> and <code>node tools/draw-size/audit.mjs /sanitized-stream/</code>) to record measured pass/fail results, <code>openSnapshots</code>, draw-size accuracy at 2.625x scale, and zero layout shift.</li>
<li>Touch selection handles across the shadow boundary and 2D canvas context retention on Chrome 159 for Android at 412 px wide.</li></ul>
<p><a href="https://html-in-canvas.page/sanitized-stream/">Open Sanitised HTML, cross-shadow selection and Temporal snapshots</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Scroll direction, :target-before/:target-after and rounded polygon()</title>
<link>https://html-in-canvas.page/scroll-directions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/scroll-directions/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>scroll-state(scrolled)</category>
<category>:target-before</category>
<category>:target-after</category>
<category>polygon(round)</category>
<description>A toolbar folded by @container scroll-state(scrolled) with no scroll listener, a CSS-only carousel fanning passed and upcoming cards via :target-before and :target-after, and drawn cards clipped with polygon(round ...).</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can @container scroll-state(scrolled), :target-before/:target-after scroll markers and rounded polygon() clip paths drive live interactive 2D canvas effects without scroll listeners?</p>
<p><strong>Short answer:</strong> Measured live in your browser below. Each section falls back cleanly when a CSS feature is not enabled yet.</p>
<p>
I wanted to see how three newer CSS features behave when they drive a 2D drawable canvas. Scroll the article below to fold its toolbar with <code>@container scroll-state(scrolled)</code> and zero scroll listeners, swipe the carousel to fan cards from <code>:target-before</code> and <code>:target-after</code>, then drag the clipped card to tilt a <code>polygon(round ...)</code> silhouette and its shadow.
</p>
<h3>How it works</h3>
<ul>
<li>In the first demo, <code>#s1-scroller</code> carries <code>container-type: scroll-state</code> and is a <code>drawable</code> child of the canvas. When you scroll it, its painted pixels change and Chrome fires the canvas <code>paint</code> event without any <code>scroll</code> listener. A probe inside the scroller matches <code>@container scroll-state(scrolled: bottom)</code> or <code>top</code> and transitions <code>--hide</code>. The <code>paint</code> handler reads <code>--hide</code> via <code>getComputedStyle()</code> and draws <code>#s1-toolbar</code> either flat (for exact hit testing when open) or split across two clipped, shaded accordion panels.</li>
<li>In the second demo, <code>#f2-deck</code> is a <code>drawable</code> child that holds the horizontal snap list, generated <code>::scroll-button()</code> arrows and <code>::scroll-marker</code> dots. Each card is a nested <code>drawable</code> child positioned against the deck so the scroller never clips its picture. On every paint, the script reads <code>--fan-side</code> and <code>--fan-tilt</code> from <code>getComputedStyle(stop, '::scroll-marker')</code> and draws the passed cards tilted left, the upcoming cards stacked right and the current card last on top.</li>
<li>In the third demo, the card's CSS <code>clip-path</code> punches transparent pixels outside the polygon in the element picture. Canvas 2D shadows (<code>shadowColor</code>, <code>shadowBlur</code>, <code>shadowOffsetX</code>, <code>shadowOffsetY</code>) trace the non-transparent alpha of <code>drawElementImage()</code>, so the shadow automatically follows notches, chevrons and rounded corners. When a browser doesn't parse <code>polygon(round ...)</code> yet, the canvas builds a matching <code>arcTo()</code> path for the shadow and clip so the radius slider stays usable.</li>
</ul>
<h3>Findings</h3>
<p>Browser support for <code>scroll-state(scrolled)</code>, <code>:target-before</code>/<code>:target-after</code> and <code>polygon(round ...)</code> varies across Chrome 130 to 160. The live checks table above reports what your browser does right now.</p>
<ul>
<li><strong>Scroll direction without scroll listeners:</strong> scrolling a drawable 2D child updates its picture and raises <code>paint</code> on the canvas. Pairing that with <code>@container scroll-state(scrolled: bottom)</code> and a registered <code>@property --hide</code> lets the canvas fold a live toolbar without touching the <code>scroll</code> event.</li>
<li><strong>Hit testing during a split draw:</strong> when a drawable element is drawn in two clipped halves to fake an accordion crease, the second <code>drawElementImage()</code> call overwrites the hit box. Drawing the toolbar in one call once <code>--hide &lt;= 0.01</code> restores exact hit boxes, and marking it <code>inert</code> past 60% folded keeps hidden inputs out of Tab order.</li>
<li><strong>Reading custom properties from <code>::scroll-marker</code>:</strong> <code>getComputedStyle(slide, '::scroll-marker').getPropertyValue('--fan-side')</code> lets the canvas inspect <code>:target-before</code>, <code>:target-current</code> and <code>:target-after</code> directly in CSS. When a browser lacks those pseudo-classes, falling back to <code>scrollLeft</code> keeps the fan working.</li>
<li><strong>Clipped alpha and canvas shadows:</strong> <code>clip-path: polygon(...)</code> is baked into the element's picture before <code>drawElementImage()</code> receives it, so 2D drop shadows follow the clipped polygon outline.</li>
<li><strong>Not verified here:</strong> real touch fling behaviour, Chrome 159 on Android and exact Chrome milestone rollout for <code>polygon(round ...)</code> in a headless run. See <code>findings/scroll-directions.md</code> for the full record.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/scroll-directions.md">findings/scroll-directions.md</a> in the repository.</p>
<p>Built on 2026-11-22 for the <code>scroll-directions</code> item in <code>tools/chrome-apis/demos.json</code>. Source checked with <code>npm run check:gfx</code> and <code>node tools/writing/check.mjs --strict</code>. Browser execution of the six live checks is <strong>not verified</strong> in this run (no headless Chromium pass or Android phone pass was run yet); every live check runs on isolated fixtures in the visitor's browser and reports its own browser support and pixel readings directly.</p>
<p>The question: can <code>@container scroll-state(scrolled)</code>, <code>:target-before</code>/<code>:target-after</code> on <code>::scroll-marker</code>, and <code>clip-path: polygon(round ...)</code> drive interactive 2D <code>drawElementImage()</code> effects without scroll listeners?</p>
<table><thead><tr><th>Experiment</th><th>Status</th><th>Notes</th></tr></thead><tbody><tr><td><code>@container scroll-state(scrolled: bottom / top)</code> toggling registered <code>@property --hide</code> inside a drawable 2D scroller</td><td>Not verified in Chromium yet</td><td>The page checks <code>CSS.supports('container-type', 'scroll-state')</code> and parses <code>@container scroll-state(scrolled: bottom)</code> via <code>CSSStyleSheet</code>, then folds <code>#s1-toolbar</code> in two hinged halves on <code>paint</code> with zero <code>scroll</code> listeners. Manual "Simulate scroll down / up" buttons toggle <code>data-sim</code> for browsers without <code>scroll-state(scrolled)</code>.</td></tr>
<tr><td>Scrolling a drawable child firing <code>paint</code> with zero scroll listeners</td><td>Not verified in Chromium yet</td><td>Live check 2 scrolls an isolated drawable child with no scroll listener attached and reads pixels from a plain <code>drawImage()</code> copy canvas to confirm <code>paint</code> ran and the scrolled band moved into view.</td></tr>
<tr><td><code>:target-before</code>, <code>:target-current</code> and <code>:target-after</code> setting <code>--fan-side</code> and <code>--fan-tilt</code> on <code>::scroll-marker</code></td><td>Not verified in Chromium yet</td><td>The carousel reads <code>getComputedStyle(stop, '::scroll-marker')</code> to tilt passed cards left, centre the active card and stack upcoming cards right. Falls back to <code>scrollLeft</code> if the pseudo-classes are not active in the visitor's browser. Live check 3 verifies <code>-1</code>, <code>0</code>, <code>1</code> on a 3-slide fixture.</td></tr>
<tr><td><code>clip-path: polygon(round ...)</code> clipped outline on a drawn card</td><td>Not verified in Chromium yet</td><td>The page reports <code>CSS.supports('clip-path', 'polygon(round 12px, 0 0, 100% 0, 100% 100%, 0 100%)')</code>. Where unsupported, a canvas <code>arcTo()</code> rounded polygon path supplies the shadow and clip so the corner-radius slider still works. Live check 4 tests both <code>CSS.supports()</code> and transparent corner pixels in a plain copy canvas.</td></tr>
<tr><td>Canvas 2D drop shadow following the clipped polygon outline</td><td>Not verified in Chromium yet</td><td>Live check 5 draws a diamond-clipped card with <code>shadowOffsetX = 14</code> and checks that the bounding corner outside the diamond stays transparent while pixels shifted off the angled edge carry shadow alpha.</td></tr>
<tr><td>Context loss and plain-HTML fallback across all three canvases</td><td>Not verified in Chromium yet</td><td>All three canvases handle <code>contextlost</code> and <code>contextrestored</code>, moving their drawable DOM back into <code>.stage.plain</code> with a visible notice. Live check 6 runs <code>stillDrawn()</code> over plain 2D copies of all three canvases.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Drawing a folding toolbar in two clipped <code>drawElementImage()</code> calls overwrites the element's hit box with the second half's transform. The draw path switches to a single unclipped <code>drawElementImage()</code> call once <code>--hide &lt;= 0.01</code>, and sets <code>toolbar.inert = true</code> past 60% folded so hidden buttons drop out of keyboard Tab order.</li>
<li>A drawable card left inside a horizontal snap scroller gets clipped by the scroller's viewport. Keeping each <code>.f2-card</code> positioned against <code>#f2-deck</code> (outside <code>#f2-track</code>'s clip, following the pattern from <code>/carousel/</code>) preserves the full picture of side cards while keeping <code>::scroll-marker</code>, <code>scroll-state(snapped)</code> and DOM order intact.</li>
<li>Applying a canvas <code>ctx.clip()</code> around a <code>drawElementImage()</code> call clips <code>ctx.shadowBlur</code> too. When falling back to <code>arcTo()</code> rounding on browsers without <code>polygon(round ...)</code>, the shadow is drawn first from the rounded polygon fill and the clipped DOM card is drawn on top.</li></ul>
<h3>Not verified</h3>
<ul><li>Headless Chromium 157 (<code>npm run check:jank -- /scroll-directions/</code> and <code>node tools/draw-size/audit.mjs /scroll-directions/</code>): run both to verify layout stability, zero timed readbacks, backing-store sizing at 412 px and DPR 2.625, and live check outcomes.</li>
<li>Chrome 159 on Android at 412 px wide by touch: scrolling <code>#s1-scroller</code> without scroll listeners, swiping <code>#f2-track</code> and tapping Pin/Lock on cards, and dragging <code>#c3</code> with <code>touch-action: none</code> while tapping Check in and Seat buttons.</li>
<li>Exact milestone availability of <code>@container scroll-state(scrolled)</code> and <code>clip-path: polygon(round ...)</code> across Chrome 157, 159 and 160.</li></ul>
<p><a href="https://html-in-canvas.page/scroll-directions/">Open Scroll direction, :target-before/:target-after and rounded polygon()</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>3D Tilt View DOM layer inspector</title>
<link>https://html-in-canvas.page/tilt-layers/</link>
<guid isPermaLink="true">https://html-in-canvas.page/tilt-layers/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>ElementGL</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>3D</category>
<category>devtools</category>
<category>hit testing</category>
<description>A five-layer web interface lifted into an exploded 3D stack on one WebGL 2 canvas, inspired by Firefox 3D Tilt View and Edge 3D View. Orbit the stack, pull the planes apart, and still click buttons, edit text and toggle filters inside every tilted layer.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can an exploded 3D layer view render each depth level of a live web interface on its own WebGL plane while keeping buttons, inputs and text selection interactive inside the tilted stack?</p>
<p><strong>Short answer:</strong> Not verified in a live browser yet. Built on one <code>ElementGL</code> WebGL 2 context with five <code>drawable</code> layers, extruded side slabs and per-layer <code>updateElementGeometry()</code> hit regions, plus a 2D isometric fallback.</p>
<p>
I wanted to see if HTML-in-canvas could rebuild Mozilla's old Firefox 3D Tilt View (Victor Porof, Firefox 11 to 46) and Microsoft Edge's 3D View panel, with one extra twist: every tilted plane stays interactive.
This experiment builds on <a href="https://html-in-canvas.page/structure-depth/">/structure-depth/</a> and <a href="https://html-in-canvas.page/layout-debug/">/layout-debug/</a> by lifting five <code>drawable</code> layers of a live mini app into an exploded WebGL 2 stack.
Drag the dark background to orbit, slide layer spacing from 0 px to 90 px, and click buttons, edit the title, toggle filters or drag across the article paragraphs right inside the tilted stack.
</p>
<h3>How it works</h3>
<p>
Firefox's classic 3D Tilt View (written by Victor Porof for Firefox 11 to 46) and Edge's 3D View panel both lift DOM depth into WebGL meshes, though those tools draw snapshots that you inspect rather than use.
Here I put five separate <code>drawable</code> elements inside one <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> and align their local coordinates to one shared app footprint.
At 0 px spacing and 0° tilt they sit flush as a single interface; as spacing grows they separate along Z.
</p>
<p>
One <code>ElementGL</code> instance owns the page's single WebGL 2 context.
Its built-in textured-quad shader draws each layer from <code>texElementSubImage2D()</code>, and a small companion colour shader on the same <code>stage.gl</code> draws the extruded side-thickness slabs, wireframe outlines and vertical corner connectors from each layer down to <code>z = 0</code>.
Because all five planes are parallel in local space, drawing from layer 0 up to layer 4 gives exact painter's order with no depth-buffer fighting.
</p>
<p>
Every visible layer receives its exact 3D <code>DOMMatrix</code> via <code>canvas.updateElementGeometry(el, { canvasTransform })</code>, followed by updating <code>el.dataset.hitTick</code> whenever the transform changes so Chromium clears its hit-test cache.
When you turn on <b>Solo selected layer</b>, the other four layers are marked <code>inert</code> and parked off-stage at a scale of 0.001 so clicks and text selection pass straight through to the soloed plane.
If WebGL 2 isn't available, the page falls back to a 2D isometric stack using five-argument <code>drawElementImage()</code>, and if HTML-in-canvas isn't available at all it moves the five elements into a plain HTML stack.
</p>
<h3>Findings</h3>
<p>Not verified in a live browser yet. Run the live checks above in Chromium with <code>#canvas-draw-element</code> enabled to record results for your device.</p>
<ul>
<li><b>Inspirations and credits:</b> Mozilla's Firefox 3D Tilt View (Victor Porof, Firefox 11 to 46), Microsoft Edge's 3D View DevTools panel, and the depth and layout experiments at <a href="https://html-in-canvas.page/structure-depth/">/structure-depth/</a> and <a href="https://html-in-canvas.page/layout-debug/">/layout-debug/</a> on this site.</li>
<li><b>One WebGL context for both DOM textures and 3D overlays:</b> sharing <code>stage.gl</code> from <code>ElementGL</code> lets the colour-slab program and the element-quad program draw into the same framebuffer without creating a second WebGL context. Restoring <code>ElementGL</code>'s program and VAO after each slab draw keeps <code>stage.quad()</code> intact.</li>
<li><b>Clip-space Z zeroing:</b> <code>DOMMatrix</code> keeps Z in CSS pixels while WebGL clips outside <code>[-w, w]</code>. Zeroing row 3 (<code>m13</code>, <code>m23</code>, <code>m33</code>, <code>m43</code>) of the clip matrix after multiplying in perspective keeps exact <code>x/w</code> and <code>y/w</code> projection with no near/far clipping.</li>
<li><b>Solo layer hit routing:</b> parking hidden layers with <code>updateElementGeometry()</code> at <code>scale(0.001)</code> and setting <code>inert = true</code> keeps upper layers from intercepting taps aimed at Layer 0 or Layer 1.</li>
<li><b>Not verified:</b> live WebGL rendering, native <code>&lt;select&gt;</code> popup placement on a tilted plane, text selection drag handles inside a perspective-transformed layer, and real Android touch orbiting at 412 px and DPR 2.625.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/tilt-layers.md">findings/tilt-layers.md</a> in the repository.</p>
<p>Not verified in a live browser yet (built on 2026-11-22). All live checks wait for a tap on the page and need Chromium with <code>#canvas-draw-element</code> enabled (C157 or newer, and A159 on Android for touch verification).</p>
<h3>Inspirations and credits</h3>
<ul><li>Mozilla Firefox 3D Tilt View (Victor Porof, Firefox 11 to 46), which rendered DOM nesting depth as a 3D exploded stack in WebGL.</li>
<li>Microsoft Edge DevTools 3D View panel, which brought back layered z-index and DOM depth inspection.</li>
<li><code>/structure-depth/</code> and <code>/layout-debug/</code> on this site, which showed perspective transforms with <code>updateElementGeometry()</code>, hit-test cache invalidation, and devtools overlays over live drawn elements.</li></ul>
<h3>What was built and what needs measuring</h3>
<table><thead><tr><th>Question</th><th>Status</th><th>What the live check tests</th></tr></thead><tbody><tr><td>Can one <code>ElementGL</code> WebGL 2 context render five <code>drawable</code> layers at separate Z depths alongside extruded side slabs, wireframes and depth connectors?</td><td>not verified</td><td>Check 1 uploads two stacked <code>drawable</code> layers under perspective into one <code>ElementGL</code> context and samples both layers via a plain 2D copy canvas.</td></tr>
<tr><td>Does <code>updateElementGeometry()</code> route <code>elementFromPoint()</code> to the tilted front layer over a back layer?</td><td>not verified</td><td>Check 2 draws overlapping buttons at <code>z = 0</code> and <code>z = 45</code> under perspective and tests both the overlapped front centre and an exposed corner of the back button.</td></tr>
<tr><td>Does parking upper layers (<code>scale(0.001)</code> plus <code>inert = true</code>) allow Solo mode clicks to reach lower layers?</td><td>not verified</td><td>Check 3 stacks two identical buttons, parks the top layer and checks that <code>elementFromPoint()</code> shifts from <code>#btnHi</code> to <code>#btnLo</code>.</td></tr>
<tr><td>Does updating <code>dataset.hitTick</code> clear Chromium's hit-test cache when a tilted layer moves?</td><td>not verified</td><td>Check 4 shifts a tilted button from left to right and records <code>elementFromPoint()</code> before and after bumping <code>dataset.hitTick</code>.</td></tr>
<tr><td>Do <code>&lt;input type="text"&gt;</code> and <code>&lt;select&gt;</code> inside a tilted <code>drawable</code> layer hit test and repaint on update?</td><td>not verified</td><td>Check 5 checks <code>elementFromPoint()</code> at the projected centres of an input and a select, then updates the input value and records the paint count.</td></tr>
<tr><td>Does the 2D isometric fallback draw and hit test using five-argument <code>drawElementImage()</code>?</td><td>not verified</td><td>Check 6 draws a sheared layer on a 2D drawable canvas with <code>drawElementImage(el, 0, 0, el.offsetWidth, el.offsetHeight)</code>, samples its pixels via a copy canvas and hit tests the button.</td></tr></tbody></table>
<h3>Design notes and things that bit during build</h3>
<ul><li><code>ElementGL.quad()</code> relies on <code>ElementGL.begin()</code> having bound its own program and VAO, so drawing a second colour shader (<code>geom.prog</code>) on <code>stage.gl</code> requires capturing and restoring <code>CURRENT_PROGRAM</code> and <code>VERTEX_ARRAY_BINDING</code> before each <code>stage.quad()</code> call.</li>
<li><code>ElementGL</code> uses premultiplied alpha blending (<code>gl.ONE</code>, <code>gl.ONE_MINUS_SRC_ALPHA</code>). Premultiplying <code>vColor.rgb * vColor.a</code> in the companion slab fragment shader keeps blending consistent without switching blend state.</li>
<li><code>DOMMatrix</code> keeps Z in CSS pixels while WebGL clips outside <code>[-w, w]</code>. Zeroing row 3 (<code>m13</code>, <code>m23</code>, <code>m33</code>, <code>m43</code>) of the clip matrix after applying perspective keeps <code>x/w</code> and <code>y/w</code> identical to <code>updateElementGeometry()</code> with no near or far plane clipping.</li>
<li>Gating <code>el.dataset.hitTick</code> behind a per-layer transform key avoids triggering a DOM mutation on unchanged repaints.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in headless Chromium 157 (C157) and recording exact pass/fail numbers.</li>
<li>Running <code>npm run check:jank -- /tilt-layers/</code> at 412 px and DPR 2.625.</li>
<li>Real touch orbiting, button tapping, text selection drag handles and native <code>&lt;select&gt;</code> picker placement on Chrome 159 for Android (A159) inside a perspective-transformed layer.</li>
<li>Frame rate when dragging the orbit camera with all five <code>drawable</code> layers uploading on live edits.</li>
<li>Screen reader output and keyboard focus ring placement across the tilted stack, especially when toggling <code>Solo selected layer</code> (<code>inert</code> on non-selected layers).</li></ul>
<p><a href="https://html-in-canvas.page/tilt-layers/">Open 3D Tilt View DOM layer inspector</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Use it: the smallest working markup for nine drop-in elements</title>
<link>https://html-in-canvas.page/use-it/</link>
<guid isPermaLink="true">https://html-in-canvas.page/use-it/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>custom elements</category>
<category>effect-frame</category>
<category>selection-fx</category>
<category>glyph-field</category>
<category>select picker</category>
<category>canvas-slot</category>
<category>dom-portal</category>
<category>dom-lens</category>
<category>datalist</category>
<description>One script tag and a few lines of markup for each of nine elements from this site's libraries: &lt;effect-frame&gt;, &lt;selection-fx&gt;, &lt;glyph-field&gt;, a select and two inputs with a picker, &lt;canvas-slot&gt;, &lt;dom-portal&gt; and &lt;dom-lens&gt;. Each listing is the markup that runs above it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/use-it/"><img src="https://html-in-canvas.page/use-it/social.jpg" width="1200" height="630" alt="The page &quot;Use it: the smallest working markup for nine drop-in elements&quot;"></a></p>
<p><strong>Question:</strong> What's the least a page on another site has to write to use each drop-in element from this site's libraries?</p>
<p><strong>Short answer:</strong> One script tag and three to nine lines of markup for each of nine elements. All nine start and take touch input in Chromium 157, each on a 2D canvas. Writing the page found that the select picker lost a selected option, which is fixed.</p>
<p>
Nine elements from this site's libraries that work on another page with one script tag and a few lines of markup. Each
box below runs the markup shown under it. Every one here draws with a 2D canvas, so the page opens no WebGL context.
The shader attribute <code>fx</code> has its own block on <a href="https://html-in-canvas.page/shader-css/">/shader-css/</a>.
</p>
<h3>How it works</h3>
<p>The markup in each box is in this page's own source, between two comments. The listing under the box is the same text with the script tag of the library put before it. A live check compares the two. This page loads each library when its section comes near the screen, so on your own page the element starts sooner than it does here.</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-22. Not yet run on a phone.</p>
<ul>
<li>Nine elements start from one script tag and the markup shown: each was upgraded or taken over by its library, and the nine listings match the markup that runs.</li>
<li>By touch at 412 px: typing in the field inside <code>&lt;effect-frame&gt;</code> worked, a double click selected a word in <code>&lt;selection-fx&gt;</code>, the link in <code>&lt;glyph-field&gt;</code> was found by a hit test, a tap opened the wheel of the select and the clock of the time input, a tap unticked the checkbox on the turned card of <code>&lt;canvas-slot&gt;</code>, typing in the copy made by <code>&lt;dom-portal&gt;</code> changed the one input, and typing a letter opened the datalist's pills.</li>
<li>Writing this page found a fault in <code>select-picker.js</code>: an option marked <code>selected</code> in the markup was lost when the library moved the options into its canvas, and the last option became the value (09:05 where the markup says 06:45). The library now keeps <code>selectedIndex</code> across the move.</li>
<li>The page opens no WebGL context: every element here draws on a 2D canvas, <code>&lt;dom-lens&gt;</code> because of <code>pipeline="2d"</code>.</li>
<li>Not verified: Chrome 159 on Android, and the snippets on a page of another origin. The libraries were loaded from this origin in every test.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/use-it.md">findings/use-it.md</a> in the repository.</p>
<p>Backlog item 30.2 in PLAN.md ("A Use it block for every library"). Measured in headless Chromium 157 (C157) on 2026-11-22 at 412 px wide. The page's four live checks pass there, and <code>node tools/use-it/check.mjs</code> drives the nine elements by touch (20 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: what is the least a page on another site has to write to use each drop-in element from this site's libraries?</p>
<p>The page is one place for all the blocks, not a block added to each library's own page. Each box runs markup that is in the page source between two region comments, and the listing under it is that text with the script tag of the library put first. A live check fetches the page and compares the two.</p>
<table><thead><tr><th>Element</th><th>Library</th><th>Result at 412 px by touch</th></tr></thead><tbody><tr><td><code>&lt;effect-frame effect="glass"&gt;</code></td><td><code>effect-frame.js</code></td><td>upgraded, 1 canvas; typing in the field inside it worked</td></tr>
<tr><td><code>&lt;selection-fx effect="marker"&gt;</code></td><td><code>selection-fx.js</code></td><td>upgraded; a double click selected a word and the marker was drawn</td></tr>
<tr><td><code>&lt;glyph-field pointer="repel"&gt;</code></td><td><code>glyph-field.js</code></td><td>upgraded; the link inside is found by a hit test; <code>explode()</code> from a button</td></tr>
<tr><td><code>&lt;select picker="wheel"&gt;</code></td><td><code>select-picker.js</code></td><td>a tap opened the wheel; the value stayed 06:45 after the fix below</td></tr>
<tr><td><code>&lt;canvas-slot&gt;</code> with <code>onrender</code></td><td><code>canvas-slot.js</code></td><td>a tap unticked the checkbox of the card drawn turned by -0.08 rad</td></tr>
<tr><td><code>&lt;dom-portal for scale="0.7"&gt;</code></td><td><code>dom-portal.js</code></td><td>typing in the copy changed the one input (C14 to C147)</td></tr>
<tr><td><code>&lt;dom-lens pipeline="2d"&gt;</code></td><td><code>dom-lens.js</code></td><td>upgraded, 1 canvas, the lens follows the pointer</td></tr>
<tr><td><code>&lt;input list picker="chips"&gt;</code></td><td><code>datalist-picker.js</code></td><td><code>input.list</code> is null; typing "t" opened a popover with three pills</td></tr>
<tr><td><code>&lt;input type="time" picker="clock"&gt;</code></td><td><code>input-pickers.js</code></td><td>a tap opened the clock</td></tr></tbody></table>
<h3>A fault this found</h3>
<p><code>select-picker.js</code> moved the options of a select into its canvas one at a time and then put the canvas in the select. While the options were outside, none was the select's option, and when they came back the select chose the last one. Markup with <code>&lt;option selected&gt;06:45&lt;/option&gt;</code> showed 09:05. <code>/select/</code> did not show this because its options are added by script and the value is set afterwards. The library now reads <code>selectedIndex</code> before the move and sets it again after. This pull request changes that one function in <code>public/lib/select-picker.js</code>.</p>
<h3>Things that bit</h3>
<ul><li><code>el.onrender = …</code> set on a <code>&lt;canvas-slot&gt;</code> before its library has loaded becomes an own property that hides the class field. The listing waits for <code>customElements.whenDefined('canvas-slot')</code> first.</li>
<li><code>effect="glass"</code> on a small form with 14 px text reads as broken. The box now holds a heading and a line of text at <code>amount="0.7"</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: all nine by touch.</li>
<li>The snippets pasted into a page on another origin. Both live hosts send <code>Access-Control-Allow-Origin: *</code> for <code>/lib/</code> (checked for a static file on 2026-11-22), and module scripts need it. Each library imports its helpers by relative path.</li>
<li>A browser with no HTML-in-canvas API. Each library says it leaves its children as plain HTML there.</li></ul>
<h3>Open ideas</h3>
<ul><li>The same page for the shader elements (<code>fx</code>, <code>&lt;physical-ui&gt;</code>, <code>&lt;live-transition&gt;</code>), one WebGL context at a time, started by a tap.</li>
<li>A check that loads each snippet in an iframe on the second origin.</li></ul>
<p><a href="https://html-in-canvas.page/use-it/">Open Use it: the smallest working markup for nine drop-in elements</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Peel this page back to read its live DOM</title>
<link>https://html-in-canvas.page/view-dom/</link>
<guid isPermaLink="true">https://html-in-canvas.page/view-dom/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>fx</category>
<category>clip-path</category>
<category>MutationObserver</category>
<category>getHTML</category>
<category>view source</category>
<description>The same peel as /view-source/, with the DOM as it is now under the page. The text is rewritten as the page changes, and only the lines that differ are replaced.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/view-dom/"><img src="https://html-in-canvas.page/view-dom/social.jpg" width="1200" height="630" alt="The page &quot;Peel this page back to read its live DOM&quot;"></a></p>
<p><strong>Question:</strong> Can the text under a peeled page be the DOM as it is now, including the canvas that draws the page, and keep up with a page that changes every second?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. <code>getHTML({ shadowRoots })</code> writes the document with the canvas that draws it, a <code>MutationObserver</code> says when to write it again, and the text lives in a shadow root so it neither appears in itself nor triggers itself. How long one write takes on a phone isn't verified: the page reports it.</p>
<p>A canvas draws this whole page. Drag the turned corner at the top right towards the bottom left, or press the first button. Under the page is its DOM as it is now, written out as HTML, and nothing else. The text is written again when the page changes. <a href="https://html-in-canvas.page/view-source/">A second page</a> has the HTML as the server sent it under it.</p>
<h3>How it works</h3>
<ul>
<li>The document doesn't scroll. <code>#sheet</code> is a scrolling box as tall as the window below the menu bar, and it holds everything from the banner to the findings. The <a href="https://html-in-canvas.page/shader-css/">fx library</a> wraps it in <code>&lt;fx-surface&gt;</code>, whose shadow root holds a canvas with <code>content="drawable"</code>. The canvas is one screen in size whatever the length of the page.</li>
<li>The effect <code>page-peel</code> is one fragment shader. It gets the picture of the page and one point, the position of the paper's corner, from the CSS properties <code>--fx-x</code> and <code>--fx-y</code>. It rolls the paper round a cylinder that lies across the direction the corner has travelled, and draws the peeled paper mirrored and faded on top of the page. Where no paper is left it writes transparent pixels and a shadow.</li>
<li>The layer under the page is ordinary DOM below the canvas: a scrolling box of text lines with no controls. It's seen through the transparent pixels.</li>
<li>Transparent pixels still take input. A <code>clip-path</code> polygon on the canvas host, computed in script from the same numbers as the shader, cuts the canvas along the roll. Taps, scrolling and text selection beyond it go to the source text.</li>
<li>The paper lying on the page is pixels. The part of the page under it would take the tap. A handle element with the same outline lies over it and takes the drag instead. A round button on the paper's corner does the same job for a keyboard: Enter peels the page and puts it back, Escape puts it back.</li>
<li>"Take the page off" rolls the page into the bottom left corner. The roll stays there to be pressed, because the layer under the page has no button of its own.</li>
<li>The text is <code>document.documentElement.getHTML()</code> with the shadow root of the canvas host passed in, so the canvas that draws the page is in it. It's written again at most four times a second while a <code>MutationObserver</code> reports changes and the page is peeled back.</li>
<li>Lines that are equal at the start and at the end of the old and new text keep their elements. The lines between are replaced and marked for a moment.</li>
<li>The text lines are built in a shadow root that isn't passed to <code>getHTML()</code>. So the text doesn't contain itself, and the observer on the document isn't told about its updates.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering, 412 px wide, on 2026-11-22. The rows above say what your browser does.</p>
<p>On this device: move the paper and scroll the page, and the number of frames the canvas drew is written here.</p>
<ul>
<li><strong>Works: one canvas draws a whole scrolling page.</strong> The page is a scrolling box inside the canvas. Scrolling it by touch, by wheel and from script raises a new frame, and elements are found at their scrolled positions. At 412 px wide and scale 2.625 the canvas is 2.24 megapixels, whatever the length of the page.</li>
<li><strong>Works: a <code>clip-path</code> on the canvas host splits input along the roll.</strong> A shader can make pixels transparent but the element behind them still takes the tap. With the host clipped, <code>elementFromPoint()</code> gives the layer under the page, and a touch swipe there scrolls the source and not the page.</li>
<li><strong>Works: the text is the page as it is.</strong> It contains <code>&lt;fx-surface&gt;</code>, its canvas with <code>content="drawable"</code>, the menu that a script built, and the <code>--fx-x</code> and <code>--fx-y</code> values, which change while the paper is dragged.</li>
<li><strong>Limit: the text is attributes and text, not state.</strong> A typed value, a ticked checkbox, a scroll position and the pixels of a canvas aren't in it. <code>outerHTML</code> also leaves out every shadow root. <code>getHTML({ shadowRoots })</code> writes the ones it is given.</li>
<li><strong>As built: setting <code>textContent</code> is reported as a change to the list of children.</strong> The clock replaces its text node each second, so the count of changes "to text" stays at 0 until the editable sentence is typed in.</li>
<li><strong>As built: a view of the DOM that is in the DOM would show itself.</strong> The text is in a shadow root, which <code>getHTML()</code> skips unless asked and which a <code>MutationObserver</code> on the document doesn't report. The table of counts is in the page, so the observer leaves its changes out by hand.</li>
<li><strong>Not verified here:</strong> the WebGPU route on a screen, and how many frames a second a phone draws while the paper is dragged and while the page scrolls. The line above this list reports both on the device that opens the page. Also open on a phone: text selection handles in the source text, and the on-screen keyboard over a document that doesn't scroll.</li>
</ul>
<p><a href="https://html-in-canvas.page/view-dom/">Open Peel this page back to read its live DOM</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Peel this page back to read the HTML the server sent</title>
<link>https://html-in-canvas.page/view-source/</link>
<guid isPermaLink="true">https://html-in-canvas.page/view-source/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>fx</category>
<category>clip-path</category>
<category>ReadableStream</category>
<category>view source</category>
<description>The whole page is drawn by one canvas. Drag its top right corner and the page rolls back like paper. Under it is the HTML of this page as the server streamed it, and nothing else.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/view-source/"><img src="https://html-in-canvas.page/view-source/social.jpg" width="1200" height="630" alt="The page &quot;Peel this page back to read the HTML the server sent&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw a whole scrolling page, roll it back from a corner under a finger, and hand input to a layer of source text under it along the roll?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. The page is a scrolling box inside one screen-sized canvas. A shader rolls it back and leaves clear pixels, and a <code>clip-path</code> on the canvas host, computed from the same numbers, sends taps and scrolling beyond the roll to the source text under it. The frame rate on a phone isn't verified: the page reports it.</p>
<p>A canvas draws this whole page. Drag the turned corner at the top right towards the bottom left, or press the first button. Under the page is its HTML as the server sent it, and nothing else. <a href="https://html-in-canvas.page/view-dom/">A second page</a> has the DOM as it is now under it.</p>
<h3>How it works</h3>
<ul>
<li>The document doesn't scroll. <code>#sheet</code> is a scrolling box as tall as the window below the menu bar, and it holds everything from the banner to the findings. The <a href="https://html-in-canvas.page/shader-css/">fx library</a> wraps it in <code>&lt;fx-surface&gt;</code>, whose shadow root holds a canvas with <code>content="drawable"</code>. The canvas is one screen in size whatever the length of the page.</li>
<li>The effect <code>page-peel</code> is one fragment shader. It gets the picture of the page and one point, the position of the paper's corner, from the CSS properties <code>--fx-x</code> and <code>--fx-y</code>. It rolls the paper round a cylinder that lies across the direction the corner has travelled, and draws the peeled paper mirrored and faded on top of the page. Where no paper is left it writes transparent pixels and a shadow.</li>
<li>The layer under the page is ordinary DOM below the canvas: a scrolling box of text lines with no controls. It's seen through the transparent pixels.</li>
<li>Transparent pixels still take input. A <code>clip-path</code> polygon on the canvas host, computed in script from the same numbers as the shader, cuts the canvas along the roll. Taps, scrolling and text selection beyond it go to the source text.</li>
<li>The paper lying on the page is pixels. The part of the page under it would take the tap. A handle element with the same outline lies over it and takes the drag instead. A round button on the paper's corner does the same job for a keyboard: Enter peels the page and puts it back, Escape puts it back.</li>
<li>"Take the page off" rolls the page into the bottom left corner. The roll stays there to be pressed, because the layer under the page has no button of its own.</li>
<li>The text is a second <code>fetch()</code> of this address with <code>cache: 'no-store'</code>, read from <code>response.body</code> chunk by chunk and shown after each chunk. The first response, the one the parser read, can't be read again from script. Its byte count is in <code>performance.getEntriesByType('navigation')</code> and is compared with the second.</li>
<li>A script in <code>&lt;head&gt;</code> records each batch of nodes the parser adds while that first response arrives. The bars under "What the server sent" are those batches.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering, 412 px wide, on 2026-11-22. The rows above say what your browser does.</p>
<p>On this device: move the paper and scroll the page, and the number of frames the canvas drew is written here.</p>
<ul>
<li><strong>Works: one canvas draws a whole scrolling page.</strong> The page is a scrolling box inside the canvas. Scrolling it by touch, by wheel and from script raises a new frame, and elements are found at their scrolled positions. At 412 px wide and scale 2.625 the canvas is 2.24 megapixels, whatever the length of the page.</li>
<li><strong>Works: a <code>clip-path</code> on the canvas host splits input along the roll.</strong> A shader can make pixels transparent but the element behind them still takes the tap. With the host clipped, <code>elementFromPoint()</code> gives the layer under the page, and a touch swipe there scrolls the source and not the page.</li>
<li><strong>Works: the text is the server's.</strong> The second request returned the same number of bytes as the response the parser read (the navigation timing entry). The text doesn't change when the page does.</li>
<li><strong>Works: a drawable canvas inside the drawn page.</strong> The inner canvas is in the outer picture and its button takes a tap. It needs <code>contain: paint</code>.</li>
<li><strong>Works: the same picture on WebGL and WebGPU.</strong> Drawn into a texture with a software WebGPU adapter, the WGSL differs from the GLSL by 0.08 of 255 per channel on average.</li>
<li><strong>Limit: the response that made the page can't be read again.</strong> Script gets its size and timing, and can watch the parser add nodes, but the text has to come from a second request. If the server answers differently the second time, the second answer is shown. The page compares the byte counts and says when they differ.</li>
<li><strong>Limit: the test server sent the page in one chunk.</strong> The text is shown after every chunk, so a response in several chunks would be seen arriving. That was not seen here.</li>
<li><strong>Not verified here:</strong> the WebGPU route on a screen, and how many frames a second a phone draws while the paper is dragged and while the page scrolls. The line above this list reports both on the device that opens the page. Also open on a phone: text selection handles in the source text, and the on-screen keyboard over a document that doesn't scroll, and how many chunks the deployed server sends.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/view-source.md">findings/view-source.md</a> in the repository.</p>
<p>Results are measured in C157 (headless Chromium 157, software rendering, 412 px wide with touch, and 1280 px wide) on 2026-11-22, by the page's live checks and by Playwright scripts that sent touch events through CDP. Nothing here was run on A159.</p>
<h3>What was built</h3>
<p>Two pages with the same peel. On each, the whole page is a scrolling box that the fx library draws through the effect <code>page-peel</code> (GLSL and WGSL in <code>lib/page-peel.js</code>). Dragging the top right corner rolls the page back.</p>
<ul><li><code>/view-source/</code>: under the page is its HTML as the server sent it (a second <code>fetch()</code> of the page, read from the response stream).</li>
<li><code>/view-dom/</code>: under the page is its DOM as it is now (<code>getHTML()</code> of the document, rewritten when a <code>MutationObserver</code> reports a change).</li></ul>
<p>The layer under the page holds numbered lines of source and nothing else: no bar, tabs or buttons. The first version was one page with a header and two tabs in that layer. The owner asked for two pages that show only the code (2026-11-22). The numbers that the bar used to show (bytes and chunks, counts of changes) are in a card in the page itself. On <code>/view-dom/</code> that card is left out of the counts, or it would count its own updates, and it is not written while the page is peeled: its numbers were six changed lines in the live text after every change, and the text scrolled to them and not to what the reader had changed.</p>
<p>Taking the page off leaves it as a roll in the bottom left corner. Pressing the roll puts the page back, so the source layer needs no button for that.</p>
<h3>Results</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Can one canvas draw a whole scrolling page?</td><td>Yes, measured.</td><td><code>#sheet</code> is <code>overflow-y: auto</code> at the height of the window below the menu. It is slotted into <code>&lt;fx-surface&gt;</code>. Touch, wheel and <code>scrollTop</code> scroll it, each raises a <code>paint</code> event and a new frame, and <code>elementFromPoint()</code> finds elements at their scrolled positions.</td></tr>
<tr><td>How large is the canvas?</td><td>2.24 MP at 412 px and scale 2.625. 28.3 MB in all canvases (jank guard).</td><td>The canvas is one screen, not the length of the page.</td></tr>
<tr><td>Can input pass through the transparent part of a shaded canvas?</td><td>Not by itself. Yes with <code>clip-path</code> on the canvas host.</td><td>Transparent pixels still hit the drawn element. <code>peelOutline()</code> repeats the shader's arithmetic and gives a polygon. With it on <code>&lt;fx-surface&gt;</code>, <code>elementFromPoint()</code> returns the layer below, and a touch swipe there scrolled the source layer and left the page where it was.</td></tr>
<tr><td>Does the script outline agree with the shader?</td><td>Yes, measured: 459 of 459 grid points.</td><td>Points within 2 px of the roll were left out.</td></tr>
<tr><td>Does the page under the peeled paper take taps on the paper?</td><td>It would. A handle element with the paper's outline (<code>clip-path</code>) covers it.</td><td>The paper lying on the page is pixels only.</td></tr>
<tr><td>Does a drawable canvas inside the drawn page work?</td><td>Yes, measured.</td><td>Its pixels are in the outer picture and its button took a touch tap. It has <code>contain: paint</code> (see <code>findings/media-tiles.md</code>).</td></tr>
<tr><td>Is the WGSL the same picture as the GLSL?</td><td>Yes, measured off screen: mean difference 0.08 of 255 per channel.</td><td>Software WebGPU adapter, drawn into a texture (<code>sameOnWebGPU()</code>).</td></tr>
<tr><td>Is the fetched HTML what the page was parsed from?</td><td>Same byte count in the test (the navigation entry's <code>decodedBodySize</code>). The text itself cannot be compared.</td><td>The first response cannot be read again from script.</td></tr>
<tr><td>How many chunks does the stream arrive in?</td><td>1 from the local test server (23 kB).</td><td>Not verified for the deployed Worker.</td></tr>
<tr><td>Does <code>getHTML()</code> show the canvas that draws the page?</td><td>Yes with <code>{ shadowRoots: [surface.shadowRoot] }</code>. <code>outerHTML</code> shows none of it.</td><td><code>/view-dom/</code> passes the root of <code>&lt;fx-surface&gt;</code> and not the root of the source layer.</td></tr>
<tr><td>Does the live text follow the page?</td><td>Attributes, text and children: yes. <code>value</code> and <code>checked</code> properties: no, until copied to attributes.</td><td>Measured by a live check with a text field.</td></tr>
<tr><td>What does a <code>MutationObserver</code> report for <code>textContent = …</code>?</td><td>A <code>childList</code> record, not <code>characterData</code>.</td><td>The clock's changes are counted under "lists of children".</td></tr>
<tr><td>Does the source view report its own updates?</td><td>No: it is in a shadow root.</td><td>Measured: two changes inside a shadow root gave no record on a document observer.</td></tr>
<tr><td>Without the API, or after a lost canvas?</td><td>The same <code>clip-path</code> goes on the page itself: the corner is cut along a straight line.</td><td>Measured with <code>--disable-blink-features=CanvasDrawElement</code> and by calling <code>fallBackToPlain()</code>.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The handle's round button sits on the paper's corner. Two checks that probed that point got the button and not what they expected. The checks probe other points.</li>
<li>A check that looked for a typed value in the serialised document found it, because the text of the check's own script is in the document. The value is now made at run time.</li>
<li>A check that counted <code>MutationObserver</code> records on the document counted the page's clock. It counts only records about its fixture.</li>
<li><code>--fx-x</code> and <code>--fx-y</code> are registered as inherited properties by the fx library. Setting them on <code>#sheet</code> on every frame of a drag would restyle every element of the page, so <code>#sheet &gt; *</code> sets both to 0. The saving was not measured.</li>
<li>Nothing inside the page may change while the corner is held: any change makes the canvas take a new picture of the whole page. The status line is written when the paper stops.</li>
<li>On a wide window the first pose uncovered the left of the source layer last, where every line starts. The source keeps to a 500 px column on the right until the page is off.</li>
<li>A fixed, full-screen box would count as an overlay in the jank guard. The page uses a box in normal flow and <code>overflow: hidden</code> on the document.</li>
<li>When the window changes height the canvas changes size and is cleared. The library draws it again on the next animation frame, so for one frame the layer under the page showed through all of it (jank guard: <code>blankFrames 1</code> on <code>/view-dom/</code>; on <code>/view-source/</code> the same frame showed the source text and was not counted as blank). The pages set the surface's <code>resized</code> hook to call <code>render()</code> in the same frame. Measured after: 0 blank frames on both.</li>
<li>On <code>/view-dom/</code> the text scrolls to the first changed line, and the clock changes every second. The text keeps still for five seconds after the reader scrolls it.</li></ul>
<h3>Not verified</h3>
<ul><li>A159: everything. In particular the WebGPU route on a screen (the test browser has no adapter that can present), the frame rate while the paper is dragged and while the page scrolls (the page writes both under "Findings" after each movement), touch selection handles in the source layer, and the on-screen keyboard over a document that does not scroll.</li>
<li>How many chunks the deployed Worker sends, and whether the second response has the same bytes as the first there. The page reports both.</li>
<li>The <code>shared</code> route (2D canvas through one WebGL context) at 2.24 MP on a phone GPU. In the test browser it ran in software.</li></ul>
<h3>Open ideas</h3>
<ul><li>A third page that shows only the lines that differ between the two sources.</li>
<li>Read the first response itself with a service worker that tees the navigation response.</li>
<li>Draw the source layer in the same canvas as a second texture, so the shader can light it.</li></ul>
<p><a href="https://html-in-canvas.page/view-source/">Open Peel this page back to read the HTML the server sent</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>100k-point WebGL chart with live DOM tooltips</title>
<link>https://html-in-canvas.page/webgl-chart/</link>
<guid isPermaLink="true">https://html-in-canvas.page/webgl-chart/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL</category>
<category>ElementGL</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<category>charts</category>
<description>100,000 data points drawn in WebGL 2 on one ElementGL canvas, with a selectable tooltip, series filter legend and pinned callout drawn as live HTML inside the same canvas.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can a WebGL 2 chart plot 100,000 interactive data points smoothly while keeping its tooltips, legend filters and inline point-annotation form as real accessible HTML inside the same canvas?</p>
<p><strong>Short answer:</strong> Built on one ElementGL WebGL 2 context with a 4-bit series bitmask uniform, a 64x64 spatial lookup grid and hit-box syncing through updateElementGeometry(). Not yet verified in Chromium 157 or on Chrome 159 for Android.</p>
<p>
I wanted to know if a WebGL 2 chart can plot 100,000 points smoothly while keeping its tooltips, series filters and pinned callouts as real accessible HTML inside the same canvas.
This experiment draws on the data-visualisation motivation in the WICG HTML-in-canvas explainer and on high-density WebGL charts such as deck.gl and Lightweight Charts.
Drag or pinch to pan and zoom, click or tap any point to inspect and copy its values, or pin an editable note to a data coordinate.
</p>
<h3>How it works</h3>
<p>
Most high-density WebGL charts (deck.gl, Lightweight Charts and similar engines) render the data on a canvas and float separate HTML nodes over it with CSS transforms.
That works until a fast pan or zoom lets the HTML layer drift a frame behind the WebGL buffer, or until screen readers and hit testing disagree with clipped elements.
Here the page opens one WebGL 2 context through <code>ElementGL</code> from <code>/lib/element-gl.js</code>, uploads 100,000 points once into static <code>ARRAY_BUFFER</code> storage, and draws three <code>drawable</code> HTML children in the same <code>paint</code> pass.
</p>
<p>
In scatter mode all 100,000 vertices are drawn in one <code>gl.drawArrays(gl.POINTS, 0, 100000)</code> call.
Each checkbox in the in-canvas legend flips a bit in a 4-bit integer uniform (<code>uMask</code>); hidden series are discarded in the vertex shader with zero VBO re-uploads.
In time-series mode the same 100,000 samples are drawn as four 25,000-vertex <code>GL_LINE_STRIP</code> traces over precomputed 500-bucket high/low OHLC range bands.
</p>
<p>
Pointer lookup doesn't scan all 100,000 points.
Scatter points are packed into a 64&times;64 flat grid (<code>cellStart</code> and <code>cellPoints</code> typed arrays) so finding the nearest visible point inspects only a handful of cells around the pointer.
Time-series samples are evenly spaced in time, so lookup jumps straight to the bucket index.
When you pan or zoom, the pinned callout's screen position is calculated from its data-space <code>(x, y)</code> coordinate, drawn with <code>stage.quad()</code>, and registered for clicks and text selection via <code>canvas.updateElementGeometry(el, { canvasTransform })</code> plus a <code>data-hit-tick</code> attribute toggle to clear Chromium's hit-test cache.
</p>
<h3>Findings</h3>
<ul>
<li>This experiment was inspired by the data-visualisation use case in the WICG HTML-in-canvas explainer (keeping accessible labels and tooltips in the same composited surface) and by high-density WebGL scatter and financial charts like deck.gl and Lightweight Charts.</li>
<li>Sharing <code>ElementGL</code>'s single WebGL 2 context avoids allocating a second GPU context on mobile. Because <code>ElementGL</code> keeps its quad program and VAO private, the chart reads <code>gl.CURRENT_PROGRAM</code> and <code>gl.VERTEX_ARRAY_BINDING</code> once after <code>stage.begin()</code>, draws the 100,000-point buffers with its own VAOs, then restores <code>ElementGL</code>'s bindings before calling <code>stage.quad()</code>.</li>
<li>Panning and zooming change only view uniforms and quad matrices. Stationary overlays whose DOM content didn't change don't need new <code>texElementSubImage2D()</code> uploads, which the upload counter under the chart tracks live.</li>
<li>Toggling <code>el.dataset.hitTick</code> after <code>updateElementGeometry()</code> clears Chromium's stale hit-test cache, and gating it on whether the element's rectangle actually changed prevents an infinite <code>paint</code> loop.</li>
<li>Hidden overlays (a dismissed tooltip, an unpinned callout, or a pinned point panned outside the plot) get <code>inert = true</code> and a hit box moved off-canvas so they stop catching clicks or Tab focus.</li>
<li>Live browser verification in Chromium 157 and on Chrome 159 for Android is not verified yet; run the live checks on your device to measure spatial lookup, WebGL 2 rendering, hit-box alignment and upload counts directly.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/webgl-chart.md">findings/webgl-chart.md</a> in the repository.</p>
<p>Not verified in a browser yet (authored 2026-11-22). Static checks (<code>npm run check:gfx</code> and <code>tools/writing/check.mjs --strict</code>) pass; every live check below is marked <code>not verified</code> until run in Chromium 157 and Chrome 159 on Android.</p>
<p>This page builds on the data-visualisation motivation in the WICG HTML-in-canvas explainer (keeping accessible chart labels and tooltips inside the same composited canvas surface) and on high-density WebGL scatter and financial charts such as deck.gl and Lightweight Charts. It plots 100,000 deterministic points across four series on one <code>ElementGL</code> WebGL 2 context (<code>/lib/element-gl.js</code>) alongside three <code>drawable</code> HTML overlays: a filter legend (<code>#chart-legend</code>), a selectable tooltip with an inline annotation form (<code>#chart-tip</code>), and a data-space pinned callout (<code>#chart-pin</code>).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Can one <code>ElementGL</code> WebGL 2 context draw 100,000 points and three <code>drawable</code> HTML overlays in the same <code>paint</code> pass?</td><td>not verified</td><td>Implemented by reading <code>gl.CURRENT_PROGRAM</code> and <code>gl.VERTEX_ARRAY_BINDING</code> once after <code>stage.begin()</code>, drawing the chart's own VAOs, then restoring <code>ElementGL</code>'s bindings before <code>stage.quad()</code>. Live check 2 tests this on an isolated fixture.</td></tr>
<tr><td>Can series filter checkboxes toggle 25,000 points per series without re-uploading vertex buffers?</td><td>not verified</td><td>Each checkbox flips one bit in <code>uMask</code> (a 4-bit integer uniform) in the scatter vertex shader, and selects which of the four 25,000-vertex <code>GL_LINE_STRIP</code> traces draw in time-series mode. Live check 3 tests <code>uMask = 1</code> against <code>uMask = 0</code> on one VBO.</td></tr>
<tr><td>Does a flat 64x64 spatial grid find the nearest of 100,000 scatter points in under 1 ms?</td><td>not verified</td><td>Uses CSR typed arrays (<code>cellStart</code>, <code>cellPoints</code>) with zero per-lookup allocations and a 5x5 cell cap around the pointer. Live check 1 times 20 queries and compares a masked query against brute force.</td></tr>
<tr><td>Does a pinned DOM callout stay aligned with its data-space <code>(x, y)</code> coordinate for clicks and text edits during pan and zoom?</td><td>not verified</td><td>Recomputed every paint via <code>dataToCss()</code>, drawn with <code>stage.quad()</code>, and synced with <code>canvas.updateElementGeometry(el, { canvasTransform })</code> plus <code>el.dataset.hitTick</code> when the rectangle changes. Live check 4 probes <code>elementsFromPoint()</code> at the translated button.</td></tr>
<tr><td>Do stationary HTML overlays avoid <code>texElementSubImage2D()</code> re-uploads while panning and zooming?</td><td>not verified</td><td><code>drawWebGL()</code> uploads only overlays named in <code>e.changedElements</code> (or missing a texture). Live check 6 checks <code>changedElements</code> across three <code>requestPaint()</code> frames.</td></tr>
<tr><td>Does the 2D fallback draw a downsampled chart and the same <code>drawable</code> overlays with five-argument <code>drawElementImage()</code>?</td><td>not verified</td><td>Falls back to a 2D context drawing every 12th scatter point (~8,300 points) plus 5-arg <code>drawElementImage()</code>, and falls back further to plain HTML overlays if <code>drawElementImage()</code> is absent. Live check 5 verifies the 2D route via a plain <code>willReadFrequently: true</code> copy canvas.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>ElementGL</code> keeps <code>#program</code> and <code>#vao</code> private, and <code>stage.quad()</code> expects them to stay bound after <code>stage.begin()</code>. Drawing the chart's own <code>GL_POINTS</code> and <code>GL_LINES</code> programs in between would break <code>stage.quad()</code> unless <code>gl.CURRENT_PROGRAM</code> and <code>gl.VERTEX_ARRAY_BINDING</code> are captured right after <code>stage.begin()</code> and restored before the quad pass. Both cached handles must also be cleared in <code>onLost</code> so a restored context captures the rebuilt program and VAO.</li>
<li>Toggling <code>el.dataset.hitTick</code> to clear Chromium's hit-test cache raises a <code>paint</code> event. Gating <code>updateElementGeometry()</code> and the attribute toggle behind a per-element <code>"x,y,w,h"</code> key stops the paint handler from looping while idle.</li>
<li>A hidden <code>drawable</code> overlay still catches clicks and Tab focus if left in place. Dismissed tooltips, unpinned callouts, collapsed legends and pins panned outside the plot set <code>el.inert = true</code> and move their hit box to <code>(-4000, -4000)</code>.</li>
<li>Pointer drag and wheel listeners on <code>&lt;canvas&gt;</code> must check <code>e.target !== canvas</code> before calling <code>setPointerCapture()</code> or <code>preventDefault()</code>, otherwise dragging the range slider, selecting text inside <code>#chart-tip</code> or opening the <code>&lt;select&gt;</code> in <code>#chart-legend</code> gets hijacked by chart panning.</li></ul>
<h3>Not verified</h3>
<ul><li>Chromium 157 (headless or desktop): run all 6 live checks on <code>/webgl-chart/</code> and verify <code>npm run check:jank -- /webgl-chart/</code> and <code>node tools/draw-size/audit.mjs /webgl-chart/</code>.</li>
<li>Chrome 159 on Android (412 px wide, touch, DPR 2.625): verify single-finger drag pan, two-finger pinch zoom, tapping points without hover, typing into <code>#tip-note</code> and <code>#pin-text</code> with the on-screen keyboard, selecting text inside <code>#chart-tip</code>, and real frame rate with 100,000 points.</li>
<li>Native <code>&lt;select&gt;</code> popup placement inside <code>#chart-legend</code> when the canvas is scrolled or zoomed on desktop and Android.</li>
<li>Screen reader announcements and keyboard Tab navigation through <code>#chart-legend</code>, <code>#chart-pin</code> and <code>#chart-tip</code> while the chart is zoomed.</li>
<li>Context loss and restoration under GPU memory pressure on Android (<code>onLost</code> / <code>onRestored</code> rebuilding the 3 VBOs and two chart programs).</li></ul>
<h3>Open ideas</h3>
<ul><li>Add WebGL 2 instanced OHLC candlesticks when zoomed below a 5% time window so individual open/high/low/close bars appear on top of the 100,000-sample trace.</li>
<li>Let visitors pin multiple notes at once by cloning a lightweight <code>&lt;template&gt;</code> into <code>drawable</code> children inside the canvas and capping the active count so GPU texture memory stays bounded.</li>
<li>Add a WebGPU compute or render route through <code>webgpu()</code> from <code>/shared/backend.js</code> to compare 100,000-point frame times against WebGL 2 on the same device.</li></ul>
<p><a href="https://html-in-canvas.page/webgl-chart/">Open 100k-point WebGL chart with live DOM tooltips</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>WebGPU immediates, external textures and MediaStreamTrack speech</title>
<link>https://html-in-canvas.page/webgpu-immediates/</link>
<guid isPermaLink="true">https://html-in-canvas.page/webgpu-immediates/</guid>
<pubDate>Sun, 22 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGPU</category>
<category>immediates</category>
<category>texture_external</category>
<category>SpeechRecognition</category>
<category>MediaStreamTrack</category>
<description>Three experiments in one page: binding a GPUTextureView from a drawable DOM card straight to a WGSL texture_external slot alongside a video, pushing per-card uniforms with pass.setImmediateData(), and feeding a video's audio track into SpeechRecognition.start(track) to drive an editable DOM caption banner in a 2D canvas.</description>
<content:encoded><![CDATA[<p><strong>Question:</strong> Can one WGSL texture_external shader sample both a video and a drawn DOM element, can pass.setImmediateData() drive four warped DOM cards with zero uniform buffers, and can SpeechRecognition.start(track) write live captions straight into a drawn DOM banner?</p>
<p><strong>Short answer:</strong> Not verified in a browser yet; each demo reports the exact API route your browser takes and falls back when a feature is missing.</p>
<p>
I wanted to test three newer Chrome APIs against HTML-in-canvas: binding a <code>GPUTextureView</code> from a drawn DOM card straight to a WGSL <code>texture_external</code> slot alongside a video, pushing per-card uniforms with <code>pass.setImmediateData()</code>, and feeding a video's audio track into <code>SpeechRecognition.start(track)</code> to drive a drawn DOM caption banner. Each section reports the path your browser took and falls back when a feature isn't there.
</p>
<h3>How it works</h3>
<p>
All three demos share the page's single WebGPU device from <code>webgpu()</code> in <code>/shared/backend.js</code> (no extra device is opened, and nothing calls <code>adapter.requestDevice()</code> directly). When WebGPU isn't available or rejects a newer binding, Demos 1 and 2 switch to a 2D canvas with <code>drawElementImage()</code> so every control stays usable.
</p>
<table>
<thead><tr><th>Capability</th><th>In this browser</th><th>How the page uses it</th></tr></thead>
<tbody>
<tr><td><code>navigator.gpu</code> + <code>drawElementImageToTexture()</code></td><td>Checking…</td><td>Uploads drawable HTML cards straight into <code>rgba8unorm</code> WebGPU textures.</td></tr>
<tr><td><code>GPUTextureView</code> in <code>externalTexture</code></td><td>Checking…</td><td>Lets one WGSL <code>texture_external</code> pipeline sample both a <code>&lt;video&gt;</code> and a drawn DOM element.</td></tr>
<tr><td><code>pass.setImmediateData()</code> / <code>setImmediates()</code></td><td>Checking…</td><td>Pushes 48 bytes of offset, tilt, wave phase and highlight per card with zero uniform buffers.</td></tr>
<tr><td><code>SpeechRecognition</code> + <code>captureStream()</code></td><td>Checking…</td><td>Sends the playing video's audio <code>MediaStreamTrack</code> to <code>recognition.start(audioTrack)</code>, falling back to <code>/media/talk.vtt</code>.</td></tr>
</tbody>
</table>
<h3>Findings</h3>
<p>
This page hasn't been measured in a browser yet; press "Run these checks" above to measure your browser, and see <code>findings/webgpu-immediates.md</code> for the verification checklist.
</p>
<ul>
<li><strong><code>GPUTextureView</code> in <code>texture_external</code> avoids duplicating shaders.</strong> When a browser accepts a single-mip 2D <code>rgba8unorm</code> view in an <code>externalTexture</code> binding, one WGSL pipeline using <code>textureSampleBaseClampToEdge()</code> can draw both <code>importExternalTexture({ source: video })</code> and a <code>drawElementImageToTexture()</code> card in the same render pass. Not verified on desktop Chrome or Android yet.</li>
<li><strong>Immediates method naming differs across Chrome builds.</strong> Chromium 157 exposed <code>GPURenderPassEncoder.prototype.setImmediates</code> with <code>maxImmediateSize</code> of 64 bytes (measured in <code>findings/webgpu-features.md</code> on 2026-11-21), while the WebGPU spec renamed the call to <code>setImmediateData()</code>. Demo 2 checks <code>setImmediateData</code> first and falls back to <code>setImmediates</code>, then to a 256-byte dynamic-offset uniform buffer, reporting whichever name the browser exposes.</li>
<li><strong><code>SpeechRecognition.start(audioTrack)</code> needs a live speech backend and unmuted audio.</strong> Headless Chromium 157 exposes <code>SpeechRecognition</code>, <code>processLocally</code> and <code>available()</code> without a speech service (measured in <code>findings/live-captions.md</code> on 2026-11-21). Muting the <code>&lt;video&gt;</code> also silences <code>captureStream()</code> in Chrome, so playback starts unmuted on user tap and falls back to <code>/media/talk.vtt</code> cues if recognition errors or produces no words within 2.5 s.</li>
<li><strong>Hit testing after WebGPU draws requires <code>updateElementGeometry()</code>.</strong> Every time a card moves or resizes in Demo 1 or Demo 2, the page passes a new <code>DOMMatrix</code> to <code>canvas.updateElementGeometry()</code> and toggles an attribute on the element to clear Chromium's hit-test cache.</li>
<li><strong>Not verified:</strong> live WebGPU presentation of <code>GPUTextureView</code>-as-<code>texture_external</code>, <code>pass.setImmediateData()</code> pixel parity against uniform buffers, and real audio track transcription from <code>/media/talk.webm</code> on Chrome desktop and Chrome for Android.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/webgpu-immediates.md">findings/webgpu-immediates.md</a> in the repository.</p>
<p>Written 2026-11-22. The live checks on <code>/webgpu-immediates/</code> are not verified in a browser yet; prior baseline facts from C157 and A159 are cited from <code>findings/webgpu-features.md</code> and <code>findings/live-captions.md</code> (2026-11-21).</p>
<p>This page puts three Chrome 130 to 160 APIs together with HTML-in-canvas:</p>
<ol><li>One WGSL <code>texture_external</code> pipeline that binds either a playing <code>&lt;video&gt;</code> via <code>device.importExternalTexture({ source: video })</code> or a drawable DOM card's <code>GPUTextureView</code> (uploaded via <code>GPUQueue.drawElementImageToTexture()</code>), or both side by side in split screen in the same render pass.</li>
<li>Four interactive drawable DOM cards warped on a subdivided mesh in one render pass, pushing 48 bytes per card (offset, tilt, wave phase, highlight and canvas size) through <code>pass.setImmediateData()</code> (or <code>pass.setImmediates()</code> where Chromium exposes the earlier name) with zero uniform buffers, falling back to a shared uniform buffer with 256-byte dynamic offsets or a 2D canvas.</li>
<li>Playing <code>/media/talk.webm</code>, capturing <code>video.captureStream().getAudioTracks()[0]</code>, and calling <code>recognition.start(audioTrack)</code> to transcribe into a selectable, editable DOM caption banner drawn over the video in a single 2D canvas, falling back to <code>/media/talk.vtt</code> cues when track recognition isn't available or emits no words.</li></ol>
<h3>Experiments</h3>
<table><thead><tr><th>Experiment</th><th>Status</th><th>Notes</th></tr></thead><tbody><tr><td><code>GPUTextureView</code> bound to a WGSL <code>texture_external</code> entry alongside <code>GPUExternalTexture</code></td><td>Not verified</td><td>Probed on startup inside a WebGPU validation error scope; switches to a 2D canvas with <code>drawElementImage()</code> and <code>drawImage()</code> if WebGPU or the view binding is rejected.</td></tr>
<tr><td>Per-element uniforms via <code>pass.setImmediateData()</code> / <code>pass.setImmediates()</code> (zero uniform buffers)</td><td>Not verified on <code>/webgpu-immediates/</code> (immediates parity measured in C157 and reported in A159 on <code>/webgpu-features/</code>, 2026-11-21)</td><td>Checks <code>GPURenderPassEncoder.prototype</code> for <code>setImmediateData</code> first, then <code>setImmediates</code>, <code>wgslLanguageFeatures.has('immediate_address_space')</code>, and <code>device.limits.maxImmediateSize &gt;= 48</code>. Falls back to a shared uniform buffer with 256-byte dynamic offsets or 2D canvas.</td></tr>
<tr><td><code>SpeechRecognition.start(audioTrack)</code> from <code>video.captureStream().getAudioTracks()[0]</code> into an editable DOM caption banner</td><td>Not verified on real hardware (headless C157 has no recognition service, measured on <code>/live-captions/</code>, 2026-11-21)</td><td>Falls back to <code>/media/talk.vtt</code> cues after an error, early <code>onend</code>, or 2.5 s with no result, while keeping the banner selectable and editable inside the 2D canvas.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><strong>Method name drift for WebGPU immediates.</strong> Chromium 157 exposed <code>GPURenderPassEncoder.prototype.setImmediates()</code> (with <code>maxImmediateSize</code> of 64 bytes), while the newer WebGPU spec uses <code>setImmediateData()</code>. Checking <code>setImmediateData</code> first and falling back to <code>setImmediates</code> lets the page use real immediates on both Chrome 157/159 and newer builds, while printing the exact method name in use.</li>
<li><strong>Two uniform buffers for split-screen <code>texture_external</code> draws.</strong> Drawing both the DOM card (<code>GPUTextureView</code>) and the playing video (<code>GPUExternalTexture</code>) in one render pass requires two separate uniform buffers (one per bind group) so the second <code>writeBuffer()</code> call doesn't overwrite the first draw's rectangle before <code>queue.submit()</code>.</li>
<li><strong>Muting silences <code>video.captureStream()</code>.</strong> In Chrome, a muted <code>&lt;video&gt;</code> produces a silent captured audio track, so Demo 3 starts playback unmuted on the visitor's Play tap and warns if the Mute speakers checkbox is ticked.</li>
<li><strong>Hit-test cache invalidation after WebGPU moves.</strong> Both Demo 1 and Demo 2 call <code>canvas.updateElementGeometry(el, { canvasTransform })</code> and toggle a <code>data-hit-tick</code> attribute on the element when its transform changes so Chromium clears its hit-test cache.</li></ul>
<h3>Not verified</h3>
<ul><li>Running the six live checks in headless Chromium 157 (<code>npm run check:jank -- /webgpu-immediates/</code> and tapping "Run these 6 checks") to measure <code>GPUTextureView</code>-in-<code>texture_external</code> validation and off-screen pixel parity.</li>
<li>Running the page on Chrome desktop and Chrome for Android (real GPU) to verify live WebGPU presentation, touch dragging on the split line, hit testing on the four warped cards, and whether <code>SpeechRecognition.start(audioTrack)</code> produces live words from <code>/media/talk.webm</code>.</li>
<li>Confirming whether Chrome 159/160 exposes <code>setImmediateData</code> or <code>setImmediates</code> on <code>GPURenderPassEncoder.prototype</code>.</li></ul>
<p><a href="https://html-in-canvas.page/webgpu-immediates/">Open WebGPU immediates, external textures and MediaStreamTrack speech</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Focus trail and heading outline</title>
<link>https://html-in-canvas.page/a11y-views/</link>
<guid isPermaLink="true">https://html-in-canvas.page/a11y-views/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>focusin</category>
<category>drawElementImage</category>
<category>headings</category>
<category>labels</category>
<description>A canvas draws a form and, when focus moves, a ring that flies from the old control to the new one while the rest is shaded. It can also mark the size of each touch target and join each label to its control. A second canvas draws an article with its headings listed beside it. Each row of the list is the heading's own pixels.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/a11y-views/"><img src="https://html-in-canvas.page/a11y-views/social.jpg" width="1200" height="630" alt="The page &quot;Focus trail and heading outline&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas show where focus went, how large each target is, which label names which control and what the heading outline is, using only the elements it draws and the positions the browser reports for them?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. focusin and getBoundingClientRect() are enough for the trail, and a rectangle of the article's picture is enough for an outline row. The browser's own focus ring is in the picture only when the focused element is inside the drawable element, and it's cut at that element's border box.</p>
<p>
Two accessibility views from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>, and two more on the same form. A canvas draws a form and, when
focus moves, a ring that travels from the control that lost focus to the one that gained it. The same canvas can mark the size of each
touch target and draw a line from each label to its control. A second canvas draws an article with a list of its headings beside it. Each
row of that list is the heading's own pixels, drawn a second time.
</p>
<h3>How it works</h3>
<ul>
<li>Each picture is one 2D canvas with <code>content="drawable"</code>. Its children are ordinary HTML and the <code>paint</code> handler draws them with <code>drawElementImage()</code>. Everything else in the picture (ring, tail, shade, target boxes, label lines, the rail) is drawn after them in the same context.</li>
<li>Focus: <code>focusin</code> bubbles to the canvas. <code>event.target</code> is the element that gained focus and <code>event.relatedTarget</code> the one that lost it. When the old element is outside the canvas, the ring starts at the nearest point of the canvas edge. The flight lasts 220 to 560 ms, longer for a longer move. With <code>prefers-reduced-motion</code> the ring is drawn at the new position at once and a straight line with an arrow head shows where it came from.</li>
<li>Positions: <code>getBoundingClientRect()</code> of a canvas child, or of an element inside one, reports where it was last drawn. "Drawn at 60%" draws the form smaller, and the ring, the target boxes and the label lines follow without any code for it.</li>
<li>Target sizes: every link, button and form control is measured as drawn. A side under 24 CSS px is red, under 48 px amber. 24 is the size in WCAG 2.2 "Target Size (Minimum)". 48 is the size Android asks for. The view measures the control's own box. It doesn't add the label of a checkbox, which also takes the tap.</li>
<li>Label lines: a line runs from the words of each <code>&lt;label&gt;</code> to its control, found through <code>control.labels</code>. The words are measured with a <code>Range</code>. A control named only by <code>aria-label</code> has a dashed outline and the name on a plate, because nothing visible names it. A control with only a placeholder is amber, a control with nothing is red, and a label whose <code>for</code> matches no control is marked.</li>
<li>Heading outline: the headings are collected from the DOM with a rule of about 15 lines. A <code>MutationObserver</code> on the article runs it again after an edit. The rail's rows are rectangles of the article's picture. The article is drawn last and whole, which puts its hit box back after the pieces.</li>
<li>The article is taller than the canvas. The canvas is <code>position: sticky</code> in a scroll container, with a spacer of the article's height after it. A <code>scroll</code> listener asks for a paint, and the handler draws the article at minus <code>scrollTop</code>. Tapping a row calls <code>scrollTo()</code> on the container and <code>focus()</code> on the heading, so the ring flies from the row to the heading.</li>
<li>Without the API, or after a lost context, both canvases are replaced by their children as plain HTML. The outline is then an ordinary list of links.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does. Real key presses and touch events were sent by <code>tools/a11y-views/check.mjs</code>.</p>
<ul>
<li><strong>Works: a focus ring is in the picture when the focused element is inside the drawable element.</strong> A 4 px red outline round a button inside a drawable <code>div</code> was found in the canvas pixels at the button's drawn position. Focus moving raised one <code>paint</code> event with the <code>div</code> in <code>changedElements</code>.</li>
<li><strong>Limit: the ring is cut at the border box of the drawable element.</strong> A button in the corner of its drawable parent kept only the part of its ring that was inside the parent. An outline round the drawable element itself isn't in its picture at all, unless <code>outline-offset</code> is negative.</li>
<li><strong>Found: no pixel change, no paint event.</strong> With <code>outline: none</code> on the focused element, moving focus raised no <code>paint</code> event. A trail that waits for <code>paint</code> wouldn't start. <code>focusin</code> fired every time, with <code>relatedTarget</code> set.</li>
<li><strong>Works: the trail follows the picture.</strong> The start and the end of the trail were at the drawn positions of the two buttons when the fixture was drawn at half size and offset.</li>
<li><strong>Found: a control drawn smaller is a smaller target.</strong> A 40 px button drawn at half size took a hit only inside its 20 px drawn box. The target view reported 20 by 20.</li>
<li><strong>Works: label text measured with a <code>Range</code> follows the picture</strong> at half size, so the line starts at the drawn words.</li>
<li><strong>Works: a row of the outline is the heading's pixels.</strong> A piece draw of the article with the heading's rectangle put the heading's colour at the row. After the pieces, one whole draw of the article put its hit box back: a point on a link in the article returned the link.</li>
<li><strong>Works: links drawn with <code>globalAlpha = 0</code> take the tap.</strong> <code>elementFromPoint()</code> at a row returned the link for that row, and the canvas pixels there came only from the canvas's own drawing.</li>
<li><strong>Found: scrolling the container raises no paint event.</strong> The page asks for one from a <code>scroll</code> listener. Changing a heading's text raises one. Changing <code>aria-level</code> raises none, so the outline is rebuilt from a <code>MutationObserver</code>.</li>
<li><strong>Works: the Tab key scrolls the article by itself.</strong> Tab from above the canvas reached a link about 710 px down the article, below the 520 px canvas. The browser scrolled the container to 480 px, which put the link in the middle of the canvas. The page didn't move. The page has no code for this.</li>
<li><strong>Works: a finger drag on the drawn article scrolls the container.</strong> A 250 px drag moved <code>scrollTop</code> by 235 px and the page by 0 px.</li>
<li><strong>Not verified here:</strong> a phone and a screen reader. TalkBack moves its own accessibility focus, which isn't DOM focus. Whether <code>focusin</code> fires when TalkBack moves to a control, and so whether the trail runs, wasn't measured. The line under the first picture counts <code>focusin</code> events: move through the form with TalkBack and read the count. The frame rate of the article scrolling under a finger wasn't measured on a phone either.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/a11y-views.md">findings/a11y-views.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21. Rows marked "input" were measured with real key presses, taps and a CDP finger drag by <code>node tools/a11y-views/check.mjs</code> at 412 px wide. The other rows are the page's 14 live checks. Not yet run on A159.</p>
<p>PLAN.md backlog group 21: "Focus ring that leads the eye" and "Heading outline beside the page". The page also builds "Label coverage check" (element catalogue, rank 3, backlog 28.25) and a target size view that was not on any list.</p>
<h3>The focus ring and the picture</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Is the browser's focus ring in the picture when the focused element is inside the drawable element</td><td>yes</td><td>A 4 px red outline at an offset of 2 px round an 80 by 30 button inside a drawable <code>div</code>. The div was drawn at 40, 40. Red pixels spanned 54, 54 to 146, 96.</td></tr>
<tr><td>Does moving focus raise a <code>paint</code> event</td><td>yes, one, if a pixel changes</td><td>The <code>div</code> was in <code>changedElements</code>.</td></tr>
<tr><td>The same with <code>outline: none</code> on the focused elements</td><td>0 paint events for 2 focus changes</td><td><code>focusin</code> fired both times, with <code>relatedTarget</code> null and then the first element. A trail must listen for <code>focusin</code>. It cannot wait for <code>paint</code>.</td></tr>
<tr><td>A ring that reaches past the border box of the drawable element</td><td>cut at the border box</td><td>The button was in the top left corner of its drawable parent. Only 120, 40 to 126, 70 was red: the part of the ring to the right of the button.</td></tr>
<tr><td>An outline round the drawable element itself</td><td>not in the picture</td><td>With <code>outline-offset: 2px</code> no red pixel, and still one paint event. With <code>outline-offset: -6px</code> red at 42, 42 to 118, 68.</td></tr>
<tr><td>Start and end of the trail when the fixture is drawn at half size at 100, 50</td><td>at the drawn positions</td><td>Centres 115, 57.5 and 115, 82.5. The page has no code for the scale: <code>getBoundingClientRect()</code> reports the drawn box.</td></tr>
<tr><td>Touch tap on a drawn field, then on a drawn button (input)</td><td>focus moves, <code>focusin</code> reaches the canvas, the trail runs</td><td>Also with the form drawn at 60%.</td></tr>
<tr><td>Three Tab presses through the drawn form (input)</td><td>name, email, phone, country in order</td><td>Moves of 170, 178 and 170 px. The page did not scroll.</td></tr>
<tr><td>A rectangle of the form's picture drawn 12% larger at the focused control, then the form drawn again with <code>globalAlpha = 0</code></td><td>the hit box is back</td><td>Without the second draw a point on another button returned the canvas.</td></tr></tbody></table>
<h3>Target sizes and labels</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A 40 by 40 button drawn at half size</td><td>a 20 by 20 target</td><td><code>getBoundingClientRect()</code> gave 20 by 20. <code>elementFromPoint()</code> returned the button at 110, 70 and the canvas at 130, 90, which is inside the full-size box.</td></tr>
<tr><td>The demo form at 100% and at 60% (input)</td><td>2 of 12 targets under 24 px, then 5 of 12</td><td>At 60% no target is 48 px or more. A tap on the 60% "Order" button still focused it.</td></tr>
<tr><td>Source of a control's name</td><td>six kinds told apart</td><td>Wrapping <code>&lt;label&gt;</code>, <code>for=</code>, <code>aria-labelledby</code>, <code>aria-label</code>, placeholder only, nothing. A label whose <code>for</code> matches no id has <code>control === null</code>.</td></tr>
<tr><td>Box of a label's words from <code>Range.getBoundingClientRect()</code> when the label is drawn at half size at 100, 60</td><td>follows the picture</td><td>10, 10 and 58.9 px wide at full size. 105, 65 and 29.5 px wide at half size.</td></tr></tbody></table>
<h3>The heading outline</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Collecting headings from the DOM</td><td>works with a rule of about 15 lines</td><td><code>h1</code> to <code>h6</code> and <code>role="heading"</code>, level from <code>aria-level</code>, 2 for a <code>role="heading"</code> with no level. Left out: <code>role="presentation"</code>, not rendered, inside <code>aria-hidden="true"</code> or <code>inert</code>.</td></tr>
<tr><td>A row of the outline as a rectangle of the article's picture</td><td>the heading's own pixels</td><td><code>drawElementImage(article, 0, 30, 150, 30, 200, 100, 75, 15)</code> put the red of the heading at the row.</td></tr>
<tr><td>The article's hit box after the pieces</td><td>back after one whole draw</td><td>A point on a link in the article returned the link. A point on the row returned the canvas.</td></tr>
<tr><td>Links drawn with <code>globalAlpha = 0</code></td><td>take the hit, leave no pixels</td><td>Two 44 px links. Each row returned its link. No pixel of the canvas had alpha.</td></tr>
<tr><td>Tap on a row (input)</td><td>the container scrolls to the heading and the heading has focus</td><td><code>scrollTo()</code> on the container and <code>focus({ preventScroll: true })</code> on the heading. The ring flies from the row to the heading while the scroll runs. The page did not move.</td></tr>
<tr><td>Changing a heading's text</td><td>1 paint event</td><td>The row changes with no code, because it is the same pixels.</td></tr>
<tr><td>Changing <code>aria-level</code></td><td>0 paint events</td><td>The list of headings is rebuilt from a <code>MutationObserver</code>.</td></tr>
<tr><td>A sticky drawable canvas in a scroll container with a spacer</td><td>scrolls natively</td><td><code>scrollHeight</code> was 160 + 240 with a 600 px child in the canvas. Setting <code>scrollTop</code> raised 0 paint events and the canvas stayed at the top of the container.</td></tr>
<tr><td>Finger drag of 250 px on the drawn article (input)</td><td>the container scrolled 235 px, the page 0 px</td><td></td></tr>
<tr><td>Tab from above the canvas to a link about 710 px down the article, below the 520 px canvas (input)</td><td>the browser scrolled the container to 480 px by itself</td><td>The link ended in the middle of the canvas. The page did not move. A second Tab went to a link at 969 px. The same with the page's own handler removed, so the page has no code for it.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The focus checks run in the hidden copy of the page (<code>apart: true</code>). <code>runBench()</code> does not empty the test stage between checks, so the third fixture was below the stage's 340 px box. Its paint event still fired, but the ring was not in the picture and the check passed for the wrong reason. Each of those checks now empties the stage first and confirms <code>:focus-visible</code> matches before it reads pixels.</li>
<li>The page takes focus back from the hidden copy after each check. A check that focused its fixture at once could lose the ring part way through. The checks wait 200 ms first.</li>
<li><code>elementFromPoint()</code> gave a stale answer for a point it had been asked about before the hit box moved. The checks toggle an attribute before each question.</li>
<li>"Next stop" took focus itself, so every move started from outside the canvas and the order restarted at the first stop. The buttons cancel <code>mousedown</code> and the page remembers the last stop.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on the phone. Open <code>/a11y-views/</code> and tap the fields: the line under the first picture counts <code>focusin</code> events and names the focused control.</li>
<li>TalkBack. Its accessibility focus is not DOM focus. Whether <code>focusin</code> fires when TalkBack moves to a control, and so whether the trail runs, was not measured. Move through the form with TalkBack and read the <code>focusin</code> count. Whether TalkBack reads the outline's links ("What a level means, level 2") and puts its own rectangle at the row was not measured either.</li>
<li>Whether a field focused by "Next stop" keeps the on-screen keyboard down (<code>inputmode="none"</code> until the field is tapped).</li>
<li>The frame rate while the article scrolls under a finger. Each frame draws the article (about 1,730 px tall at 412 px wide) once and one piece of it per heading.</li>
<li>Windows High Contrast and forced colours. The ring, the tail and the plates use fixed colours.</li>
<li><code>:focus-visible</code> after a touch tap on a button. The canvas ring does not depend on it.</li></ul>
<h3>Open ideas</h3>
<ul><li>The trail for a screen reader's accessibility focus, if a page can learn where it is.</li>
<li>A reading-order view: the order a screen reader visits the drawn content, as a path, beside the Tab order of <code>/focus-path/</code>.</li>
<li>A contrast view: text pixels of each element read from a <code>drawImage()</code> copy on a tap, with the measured ratio on a plate.</li>
<li>The outline for a whole page, with the page's sections drawn by one canvas.</li></ul>
<p><a href="https://html-in-canvas.page/a11y-views/">Open Focus trail and heading outline</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Accordion from &lt;details&gt; that unfolds</title>
<link>https://html-in-canvas.page/accordion/</link>
<guid isPermaLink="true">https://html-in-canvas.page/accordion/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>details</category>
<category>captureElementImage</category>
<category>drawElementImage</category>
<category>::details-content</category>
<description>Four &lt;details name&gt; elements drawn by a canvas. The closed and open pictures of each one are joined by a paper fold: the content is drawn as sheared strips, from a snapshot when closing and from the live element when opening.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/accordion/"><img src="https://html-in-canvas.page/accordion/social.jpg" width="1200" height="630" alt="The page &quot;Accordion from &lt;details&gt; that unfolds&quot;"></a></p>
<p><strong>Question:</strong> A <code>&lt;details&gt;</code> element has two pictures, closed and open, and the browser switches between them in one step. Can a canvas hold both and animate between them?</p>
<p><strong>Short answer:</strong> Yes. A snapshot taken while the element is open gives the open picture after it has closed. The content of a closed element can't be drawn any other way.</p>
<p>
Four <code>&lt;details&gt;</code> elements with the same <code>name</code>, drawn by a canvas. Tap a heading. The browser opens that one and closes the other in the same instant.
The canvas has a picture of the closed one from before it closed and a live picture of the one that opened, and joins them with a fold: the content is cut into strips that open like folded paper.
The controls inside the open section work, also while it unfolds.
</p>
<h3>How it works</h3>
<p>A closed <code>&lt;details&gt;</code> has no box for its content, so its picture is only the summary. The open picture exists only while it's open. An animation between the two needs both at once, and the browser changes the state in one step.</p>
<p><b>Closing.</b> On every paint while a section is open and not animating, the canvas calls <code>captureElementImage()</code> and keeps the result. When a later paint finds the section closed, the content strips are drawn from that snapshot, folding shut.
This also covers a section that the browser closed because another one with the same <code>name</code> was opened: the page gets no warning before that happens.</p>
<p><b>Opening.</b> The section is already open in layout, so the strips are drawn from the live element. Each strip is a clipped <code>drawElementImage()</code> with a transform that squashes it vertically and shears it sideways, alternating direction, and a dark or light fill over it.
A last draw with no alpha puts the hit region of the whole section at its final size, so its controls can be used during the fold.</p>
<p><b>Positions.</b> The layout jumps at once. The canvas ignores the layout positions and stacks the sections itself, using an animated height for each.</p>
<p><b>CSS route.</b> With "CSS height transition" the page does none of that. <code>interpolate-size: allow-keywords</code> and a transition on <code>::details-content</code> make the browser animate the height, each frame raises a <code>paint</code> event, and the canvas draws every section where layout puts it.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 a <code>&lt;details drawable&gt;</code> draws in both states. Closed, its picture and its <code>offsetHeight</code> are the summary only.</li>
<li>A snapshot from <code>captureElementImage()</code> taken while the element was open still draws the open content after it has closed. This is the only way found to get the open picture of a closed <code>&lt;details&gt;</code>.</li>
<li>The content of a closed <code>&lt;details&gt;</code> can't be drawn on its own: a nested <code>drawable</code> content element throws "No cached paint record" while closed. The check below records it.</li>
<li>Opening one <code>&lt;details name&gt;</code> closes the other synchronously. One <code>paint</code> event shows both changes, so both animations start on the same frame.</li>
<li>A clipped draw of part of an element, under a shear, works, and several draws of one element in a frame are allowed. The hit region is that of the last draw, so the page ends with a draw at alpha 0 in the resting position.</li>
<li>The CSS route works in a canvas: a height transition on <code>::details-content</code> raises a <code>paint</code> event for each frame.</li>
<li>Not verified: frame rate on a phone, and what a screen reader announces during the fold (the elements and their states are the native ones).</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/accordion.md">findings/accordion.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, 412 px wide, touch emulation) on 2026-11-21. Not yet run on A159.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>&lt;details drawable&gt;</code> in both states</td><td>works</td><td>Closed, <code>offsetHeight</code> and the picture are the summary only.</td></tr>
<tr><td>Get the open picture of a closed <code>&lt;details&gt;</code></td><td>only from a snapshot</td><td><code>captureElementImage()</code> taken while it was open still draws the content after it has closed.</td></tr>
<tr><td>Draw the content of a closed <code>&lt;details&gt;</code> on its own (content element has <code>drawable</code>)</td><td>fails</td><td><code>drawElementImage()</code> throws <code>InvalidStateError</code>: "No cached paint record for element". The content has no box while closed.</td></tr>
<tr><td>Opening one <code>&lt;details name&gt;</code> closes the other</td><td>synchronously</td><td><code>a.open</code> is false in the same task as <code>b.open = true</code>. One <code>paint</code> event shows both changes, so both animations start on the same frame. The page gets no event before the close.</td></tr>
<tr><td>Detect the change</td><td>compare <code>open</code> on each paint</td><td>The <code>toggle</code> event is a later task. The first paint after the change already has the new layout.</td></tr>
<tr><td>Part of an element drawn clipped under a shear, several times a frame</td><td>works</td><td>Six strips of the content, each one clip plus <code>transform(1, 0, shear, squash, 0, 0)</code> plus <code>drawElementImage()</code>.</td></tr>
<tr><td>Where input goes during the fold</td><td>last draw</td><td>The page ends each frame with a draw at <code>globalAlpha = 0</code> at the resting position. Controls in the opening section work during the fold.</td></tr>
<tr><td>A summary drawn away from its layout position</td><td>works</td><td><code>elementFromPoint()</code> and real taps reach it.</td></tr>
<tr><td>CSS route: <code>interpolate-size: allow-keywords</code> and a height transition on <code>::details-content</code>, canvas only redraws</td><td>works</td><td>19 <code>paint</code> events with 19 different heights in a 0.3 s transition in a check fixture.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The layout jumps at once when a section opens, so <code>offsetTop</code> of the sections below is no use during the animation. The page stacks the sections itself with an animated height for each.</li>
<li>A check that added the CSS-route rules in a <code>&lt;style&gt;</code> element just before opening saw no transition (two heights). With the rules in the page's stylesheet from the start it runs.</li></ul>
<h3>Not verified</h3>
<ul><li>Frame rate of the fold on a phone.</li>
<li>What a screen reader announces during the fold. The elements and their states are the native ones.</li>
<li>Find-in-page opening a closed section (<code>hidden=until-found</code> behaviour of <code>&lt;details&gt;</code>), which would also change <code>open</code> without warning. The paint-time comparison should cover it. Searching the page for a word in a closed section would verify it.</li></ul>
<h3>Ideas built</h3>
<ul><li>"Accordion that unfolds" from <code>public/elements/ideas.js</code> (structure).</li></ul>
<p><a href="https://html-in-canvas.page/accordion/">Open Accordion from &lt;details&gt; that unfolds</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>An agent operating a canvas UI</title>
<link>https://html-in-canvas.page/agent-view/</link>
<guid isPermaLink="true">https://html-in-canvas.page/agent-view/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebMCP</category>
<category>Prompt API</category>
<category>ariaNotify</category>
<category>fx</category>
<description>A form drawn through a shader offers three WebMCP tools. Each tool call turns the panel to face you, moves a marker to the field and types into the real input. The Prompt API can plan the calls from a sentence and describe a picture of the canvas.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/agent-view/"><img src="https://html-in-canvas.page/agent-view/social.jpg" width="1200" height="630" alt="The page &quot;An agent operating a canvas UI&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas show what an agent is doing to a live form (which field, which value), and can WebMCP tools and the Prompt API drive it?</p>
<p><strong>Short answer:</strong> A tool call sets four CSS custom properties and the input's value; a shader draws the marker and the lean from them. WebMCP and the Prompt API were missing or without a model in the test browser, so those paths aren't verified.</p>
<p>
A booking form drawn through a shader, leaning in perspective. It offers three tools to an agent. Press "Run the scripted agent", or type
a request: each tool call turns the panel to face you, moves a marker to the field and types into the real input.
</p>
<h3>How it works</h3>
<p>
The form is one drawable element. <a href="https://html-in-canvas.page/lib/shader-fx.js"><code>fx</code></a> uploads it to a texture on every <code>paint</code> and a
fragment shader draws it, with WebGPU when that works and WebGL otherwise. The shader has no state of its own: the lean and the marker
position are CSS custom properties on the form, and the tool code only changes those properties and the form's values.
<code>ariaNotify()</code> announces each step, because a marker drawn by a shader isn't in the accessibility tree.
</p>
<p>
The same three tool objects are used by every caller on this page: the browser's agent through WebMCP when
<code>navigator.modelContext</code> exists, the scripted run, the Prompt API planner and the pattern matcher. The log names the caller of each
call.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The canvas can show what an agent does with no extra state.</strong> A tool call sets four custom properties and the input's value. CSS transitions animate the properties and the shader reads them each frame. The tool's promise resolves after the animation, so an agent is paced by what the reader sees.</li>
<li><strong>Typing by a tool goes into the real input.</strong> The value is set one character at a time with an <code>input</code> event for each, and the element repaints into the texture each time. The tool doesn't call <code>focus()</code>, so it doesn't take the keyboard from the reader.</li>
<li><strong>The form takes clicks where it is drawn while it leans.</strong> The effect's <code>geometry()</code> matrix goes to <code>updateElementGeometry()</code>, and the live check finds four controls with <code>elementFromPoint()</code> at their drawn positions, within 3 px of where the matrix puts them.</li>
<li><strong><code>navigator.modelContext</code> is missing from the test browser</strong> (headless Chromium 157), so registration with WebMCP hasn't been run. The code tries <code>registerTool()</code> and then <code>provideContext()</code>. Which one Chrome 159 has, and what the agent passes to <code>execute()</code>, isn't verified.</li>
<li><strong>The Prompt API couldn't be run either.</strong> <code>LanguageModel.availability()</code> reports "downloadable" in the test browser and nothing can be downloaded there. <code>prompt()</code> with a <code>responseConstraint</code> resolved with a sentence that starts "On-device" instead of JSON, so the page fell back to the pattern matcher. The planner and the image prompt are written from the specification and aren't verified with a model.</li>
<li><strong>A form control must not be named <code>length</code>.</strong> <code>form.elements.length</code> is the number of controls, so a field with that name can't be reached by name. The boat length field is named <code>boat_length</code>.</li>
<li><strong>The picture for the model is the shaded one.</strong> It is copied from the canvas, so it includes the lean, the dimming and the marker. A model reading it sees what the reader sees, which isn't the same as the DOM.</li>
<li><strong>Not verified:</strong> everything that needs the WebMCP flag or origin trial, the on-device model on a phone, and WebGPU on screen (the test browser has no adapter that can present).</li>
</ul>
<p><a href="https://html-in-canvas.page/agent-view/">Open An agent operating a canvas UI</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Animated image formats as paint clocks</title>
<link>https://html-in-canvas.page/animated-images/</link>
<guid isPermaLink="true">https://html-in-canvas.page/animated-images/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>paint event</category>
<category>changedElements</category>
<category>&lt;img&gt;</category>
<category>SVG</category>
<description>Ten animated images as canvas children: GIF, APNG, WebP, AVIF, three SVG files, an inline SVG, a CSS background and a GIF that plays once. Each one swings a sign by one step for each paint event it raises, so a format that raises one event per frame keeps its sign in step with the others.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/animated-images/"><img src="https://html-in-canvas.page/animated-images/social.jpg" width="1200" height="630" alt="The page &quot;Animated image formats as paint clocks&quot;"></a></p>
<p><strong>Question:</strong> Which animated image formats raise <code>paint</code> once per frame when the image is a child of a drawable canvas?</p>
<p><strong>Short answer:</strong> All that were tried, in Chromium 157: GIF, APNG, WebP and AVIF, SVG with stepped SMIL or CSS animation, inline SVG, a CSS background image, <code>&lt;picture&gt;</code>, <code>&lt;object&gt;</code> and <code>content: url()</code> each raised 12.5 events a second for 12.5 frames a second. A continuous SMIL animation raised one per display frame. A GIF that plays once stopped raising them after its last frame. An SVG file in an <code>&lt;img&gt;</code> stopped when the place it was drawn at left the window, and the raster formats did not.</p>
<p>
<a href="https://html-in-canvas.page/paint-clocks/">Paint clocks</a> found that an animated GIF in a drawable canvas raises <code>paint</code> once for each of its
frames. I wanted to know if the same is true of the other ways to put an animated image in a page. Every file here shows the same spinner: 12 frames
of 80 ms, which is 12.5 frames a second. Each is a <code>drawable</code> child of one canvas, and the canvas counts the
<code>paint</code> events that name it. Nothing on the page calls <code>requestAnimationFrame()</code> or starts a timer.
</p>
<h3>How it works</h3>
<p>A drawable canvas gets a <code>paint</code> event when the picture of one of its <code>drawable</code> descendants changes, and <code>event.changedElements</code> lists the descendants that changed. When an animated image shows its next frame the element's picture changes, so the image is in that list. The handler on this page redraws the whole canvas on every event and adds one to a tile's count when the list holds that tile's clock.</p>
<ul>
<li><b>The clock stays still.</b> Drawing an element at a new place raises a <code>paint</code> event that names it. Each clock is drawn at the same place every time, and the part that moves, the sign, is a separate <code>drawable</code> element, so the events of a swinging sign aren't counted as frames.</li>
<li><b>Formats that aren't an <code>&lt;img&gt;</code>.</b> The inline SVG and the CSS background are inside a <code>drawable</code> <code>&lt;div&gt;</code>. The event names the div.</li>
<li><b>Restart.</b> The buttons set each image's address again with a new query string, which starts the animation from its first frame. The inline SVG is reset with <code>setCurrentTime(0)</code>.</li>
<li><b>Lottie isn't here.</b> A Lottie file isn't an image format that the browser animates. A player script changes an inline SVG or a canvas from <code>requestAnimationFrame()</code>, so its clock is the script's frame loop, and this site has no player library.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.</p>
<ul>
<li><b>Every frame-based format raised one <code>paint</code> per frame.</b> GIF, APNG, WebP and AVIF in an <code>&lt;img&gt;</code> each gave 12.5 paint events a second for files of 12.5 frames a second. So did an SVG file with a stepped SMIL animation and one with a stepped CSS animation.</li>
<li><b>The image doesn't have to be an <code>&lt;img&gt;</code>.</b> A GIF as a CSS <code>background-image</code>, a <code>&lt;picture&gt;</code> that chose its AVIF source, an <code>&lt;object&gt;</code> that loaded the SVG file and a div with <code>content: url(clock.gif)</code> gave 12.5 a second. The event names the <code>drawable</code> element that holds the image.</li>
<li><b>An inline SVG with the same stepped SMIL animation gave a less even count.</b> 9.4 a second in the live check's canvas in three runs, and 12 to 15 in the demo. The animation is sampled by the page's own frames, not by an image decoder.</li>
<li><b>A continuous animation has no frame rate.</b> The SVG whose dot turns smoothly raised 59.4 events a second, one for each frame of a 60 Hz display, so an effect that counts its events runs about five times faster than one that counts the frames of a GIF.</li>
<li><b>A finished animation is a stopped clock.</b> A GIF with a loop count of one raised 13 events for its 12 frames and none in the second after. Setting its address again with a new query string played it again.</li>
<li><b>Two images in one canvas are named separately.</b> A GIF and an APNG in one canvas were each named 12.5 times a second in <code>changedElements</code>, in 12.5 paint events a second: frames that fall in the same display frame share one event.</li>
<li><b>An SVG file in an <code>&lt;img&gt;</code> stops when the place it is drawn at is off screen.</b> With the canvas scrolled above the window for 2.3 s, both stepped SVG files and the smooth one showed 0 events in the last second. The four raster formats, the inline SVG and the CSS background carried on at 12 to 13, and the handler ran 55 times while the canvas couldn't be seen. With only the lower rows of the canvas on screen, the SVG files in the rows above stopped and the one below ran, so the test is the drawn place of the image, not the place of the canvas.</li>
<li><b>Not built: Lottie.</b> It is a script that animates an inline SVG or a canvas from <code>requestAnimationFrame()</code>, not an image format, and this site has no player library.</li>
<li><b>Not verified:</b> everything on a phone. In particular whether Chrome on Android decodes all four raster formats at the stored rate, whether it pauses raster images when the canvas is off screen (the line under the demo counts those events), and the rate of the smooth SVG on a 90 or 120 Hz display.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/animated-images.md">findings/animated-images.md</a> in the repository.</p>
<p>Idea 22.6 of the backlog in PLAN.md. Measured in headless Chromium 157 (C157) on 2026-11-21 at 412 px wide. The page's seven live checks pass there, and <code>node tools/animated-images/check.mjs</code> drives the demo (22 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: which animated image formats raise <code>paint</code> once per frame when the image is a child of a drawable canvas?</p>
<p>Every test file shows the same spinner, 12 frames of 80 ms (12.5 frames a second). The files are in <code>public/animated-images/</code>. A rate below is the number of <code>paint</code> events per second whose <code>changedElements</code> named the element, counted over 1.6 s in a live check unless it says otherwise.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>GIF, APNG, WebP, AVIF in an <code>&lt;img&gt;</code></td><td>12.5 each</td><td>One event per frame for all four raster formats.</td></tr>
<tr><td>SVG file in an <code>&lt;img&gt;</code>, SMIL with <code>calcMode="discrete"</code></td><td>12.5</td><td>One event per step.</td></tr>
<tr><td>SVG file in an <code>&lt;img&gt;</code>, CSS animation with <code>steps(12)</code></td><td>12.5</td><td>One event per step.</td></tr>
<tr><td>SVG file in an <code>&lt;img&gt;</code>, continuous SMIL rotation</td><td>59.4</td><td>No frames of its own: one event per display frame.</td></tr>
<tr><td>GIF as a CSS <code>background-image</code> of a <code>drawable</code> div</td><td>12.5</td><td>The event names the div.</td></tr>
<tr><td><code>&lt;picture&gt;</code> with an AVIF <code>&lt;source&gt;</code> and a GIF fallback</td><td>12.5</td><td></td></tr>
<tr><td><code>&lt;object data="smil.svg"&gt;</code></td><td>12.5</td><td></td></tr>
<tr><td>A div with <code>content: url(clock.gif)</code></td><td>12.5</td><td></td></tr>
<tr><td>Inline SVG with the stepped SMIL animation, in a <code>drawable</code> div</td><td>9.4 in the live check (three runs), 12 to 15 in the demo</td><td>Sampled by the page's frames. The count is less even than for an image file. The live check allows 45% either way for it.</td></tr>
<tr><td>GIF with a loop count of one</td><td>13 events for 12 frames, then 0 in the next second</td><td>A finished image raises nothing. A new query string on <code>src</code> plays it again.</td></tr>
<tr><td>GIF and APNG in one canvas</td><td>each named 12.5 times a second, in 12.5 events a second</td><td>Frames that fall in the same display frame share one event, and <code>changedElements</code> lists both images.</td></tr>
<tr><td>A div with a plain background</td><td>0 in 1 s</td><td>The base line.</td></tr>
<tr><td>Canvas scrolled above the window for 2.3 s (tool script, count for the last second)</td><td>GIF, APNG, WebP, AVIF, inline SVG and CSS background: 12 to 13. All three SVG files in <code>&lt;img&gt;</code>: 0</td><td>The handler ran 55 times while the canvas was off screen.</td></tr>
<tr><td>Only the lower 240 px of the canvas on screen</td><td>The SVG files in rows above the window: 0. The SVG file in the bottom row: 60</td><td>An SVG image stops by the place it is drawn at, not by the place of its canvas.</td></tr>
<tr><td>An SVG image drawn at y = 1500 in a 1600 px canvas whose top is on screen (scratch page, 2 s)</td><td>8.5, against 12.5 for a GIF drawn the same way</td><td>The same result from a fixture: it ran for part of the time and stopped.</td></tr>
<tr><td>An image that is never drawn, canvas on screen (scratch page)</td><td>SVG 12.5, GIF 12.5</td><td>Not being drawn does not stop either kind.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the drawing and shows the elements as plain HTML. Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The page reuses <code>mount()</code>, <code>ticked()</code> and <code>meter()</code> from <code>/paint-clocks/kit.js</code>. The clocks are drawn at a fixed place and the swinging signs are separate <code>drawable</code> elements, because an element drawn at a new place raises a <code>paint</code> event that names it.</li>
<li>An <code>&lt;svg&gt;</code> element has no <code>offsetWidth</code>, so the inline SVG sits in a <code>drawable</code> div and the div is what is drawn and named.</li>
<li>The first version of the status line showed 0 for the SVG tiles before the page was scrolled. They were below the window. That is how the off-screen rule for SVG images was found.</li>
<li>A string replace that removed <code>width="64" height="64"</code> from the inline SVG also removed it from the background <code>&lt;rect&gt;</code>.</li>
<li>The test stage for live checks is 340 px tall and clips. Fixtures are 60 px tall so that five fit at once. A clipped SVG fixture would have stopped.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the demo by touch, and that all four raster formats decode and run at 12.5 a second there.</li>
<li>Whether Chrome on Android pauses raster images, the inline SVG or the CSS background while the canvas is off screen. The line under the demo counts paint events that arrive while the canvas is off screen.</li>
<li>The rate of the continuous SVG on a 90 or 120 Hz display.</li>
<li>Why the inline SVG gives 9.4 events a second in the live check and 12 to 15 in the demo.</li>
<li>How long an SVG image keeps running after its drawn place leaves the window. It showed 0 in the last second after 2.3 s.</li>
<li>Whether a GIF that plays once and is below the window at load starts before it is scrolled into view. The demo's one-shot tile showed 2 events in the second after it was first scrolled into view, 2.5 s after load.</li>
<li>Lottie. Not built: it is a script that animates an inline SVG or a canvas from <code>requestAnimationFrame()</code>, and <code>public/vendor/</code> has no player.</li></ul>
<p><a href="https://html-in-canvas.page/animated-images/">Open Animated image formats as paint clocks</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Sound driving DOM</title>
<link>https://html-in-canvas.page/audio/</link>
<guid isPermaLink="true">https://html-in-canvas.page/audio/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Web Audio</category>
<category>&lt;audio&gt;</category>
<category>@property</category>
<category>WebGPU</category>
<description>An AnalyserNode writes four band levels to CSS custom properties. A shader that draws a working audio player card reads them as uniforms.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/audio/"><img src="https://html-in-canvas.page/audio/social.jpg" width="1200" height="630" alt="The page &quot;Sound driving DOM&quot;"></a></p>
<p><strong>Question:</strong> Can sound analysis drive the shader that draws live DOM, with CSS custom properties as the only link?</p>
<p>
The card below is HTML drawn through a fragment shader. Press play on its <code>&lt;audio&gt;</code> controls. An <code>AnalyserNode</code>
writes the level of four frequency bands to four CSS custom properties. The shader reads them as uniforms and the bars read them with CSS.
The text field and the buttons keep working.
</p>
<h3>How it works</h3>
<ul>
<li>The <code>fx</code> library registers <code>--fx-amount</code>, <code>--fx-x</code>, <code>--fx-y</code> and <code>--fx-progress</code> as numbers and passes them to every effect. This page uses them as four band levels from 0 to 1.</li>
<li>The page never calls a canvas API. It sets four style properties per frame.</li>
<li>An <code>AudioContext</code> stays suspended until the person taps, so the analysis starts on the first <code>play</code> event.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: <code>&lt;audio controls&gt;</code> in a canvas.</strong> The native audio controls are drawn, and play, seek and volume work under the shader because the element keeps its layout position for hit testing.</li>
<li><strong>Works: custom properties as the link.</strong> One set of four numbers drives CSS inside the element and the shader that draws the element. Nothing else connects the audio code to the drawing code.</li>
<li><strong>Works: analysis with no gesture, off line.</strong> <code>OfflineAudioContext</code> decodes and analyses the clip without a tap, which is how the second live check gets band levels. Live analysis needs the tap.</li>
<li><strong>Cost: one upload per frame.</strong> The bars change the DOM every frame, so the element is uploaded to the texture every frame while sound plays. With the bars removed, only the uniforms change and the texture is reused.</li>
<li><strong>Built, not heard: the delay.</strong> The picture is held back by <code>AudioContext.playbackStats.averageLatency</code> where the browser has it, else <code>outputLatency</code>. The test browser has no sound card and reports 0, so whether picture and sound line up on a phone or on Bluetooth headphones is for a person to judge. The checkbox turns the delay off for comparison.</li>
<li><strong>Not verified here:</strong> audible output and timing on a real device (the test browser has no sound card), the microphone, and the WebGPU route on screen.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-and-sound.md">findings/video-and-sound.md</a> in the repository.</p>
<h3>Sound driving DOM (<code>/audio/</code>)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>AnalyserNode</code> levels written to <code>--fx-amount</code>, <code>--fx-x</code>, <code>--fx-y</code>, <code>--fx-progress</code> each frame</td><td>the shader and plain CSS both follow</td><td>The four registered properties are the only link between the audio code and the drawing.</td></tr>
<tr><td>Native <code>&lt;audio&gt;</code> controls under the shader</td><td>work</td><td>Play was pressed by touch on the drawn control.</td></tr>
<tr><td>Text field and button in the same card</td><td>work</td><td></td></tr>
<tr><td><code>OfflineAudioContext</code> with an <code>AnalyserNode</code> and <code>suspend(t)</code></td><td>gives band levels with no tap</td><td>Live analysis needs a tap, because a new <code>AudioContext</code> starts suspended.</td></tr>
<tr><td>GLSL and WGSL versions of the page's effects</td><td>same picture, mean difference 0.00 to 0.35 of 255</td><td>Compared off screen with a software WebGPU adapter.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/audio/">Open Sound driving DOM</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Blocks to handle: legend, summary, figure, template and a table of buttons</title>
<link>https://html-in-canvas.page/block-play/</link>
<guid isPermaLink="true">https://html-in-canvas.page/block-play/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>fieldset</category>
<category>legend</category>
<category>details</category>
<category>figure</category>
<category>template</category>
<category>table</category>
<category>drawElementImage</category>
<description>Fieldsets stacked as folders with their legends as tabs, a &lt;details&gt; element unrolled by a lever, figures fanned out as prints with their alt text, one &lt;template&gt; cloned into tickets that move between layouts, and a minefield that is a table of buttons.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/block-play/"><img src="https://html-in-canvas.page/block-play/social.jpg" width="1200" height="630" alt="The page &quot;Blocks to handle: legend, summary, figure, template and a table of buttons&quot;"></a></p>
<p><strong>Question:</strong> Can a 2D canvas turn block elements into things to pick up, pull and press (stacked fieldsets, a details worked by a lever, turned figures, clones of a template, a table of buttons) while every tap still goes to the element?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. The element drawn last takes the input where two overlap, so drawing order is the stacking order. A turned figure is tapped at its turned place. Twelve template clones each had their own hit region, and 36 of 36 buttons in a drawn table were found. A closed details is only as tall as its summary, so the lever opens it and the canvas clips the draw.</p>
<p>
Five ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a> in which the canvas turns a block element into a thing to pick up, pull or
press: fieldsets as a stack of folders, a details element worked by a lever, figures as prints on a table, one template cloned into many
tickets, and a table of buttons as a minefield. Every part that takes a tap is the element itself.
</p>
<h3>How it works</h3>
<ul>
<li><b>Drawing order is stacking order.</b> A 2D canvas has no <code>z-index</code> for the elements it draws. The folders, the prints and the tickets are drawn from the back to the front, and the element drawn last takes the input where two overlap.</li>
<li><b>Transforms carry the hit region.</b> A print or a ticket drawn under <code>ctx.rotate()</code> and <code>ctx.scale()</code> is tapped where it is seen.</li>
<li><b>Canvas-drawn parts take input through the canvas.</b> The lever isn't an element. A <code>pointerdown</code> whose target is the canvas itself is a press on a part that no element covers.</li>
<li><b>Frames.</b> Each demo asks for frames only while something moves.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.</p>
<ul>
<li><b>Drawing order is the only stacking order, and it's enough.</b> Of two overlapping fieldsets the one drawn last took the input in the overlap, and the tab of the other was found above it. Three folders are reordered by changing the order of three draws.</li>
<li><b>A legend can hold the tab's button.</b> The legend's box (80 by 30 px in the check) is at the top of its fieldset, and <code>margin-left</code> moves it along. The fieldset has no background of its own, so the space beside the tab is clear.</li>
<li><b>A closed <code>&lt;details&gt;</code> can't be drawn part open.</b> Closed, the element was 24 px tall, the height of its summary, while its content still reported a height of 48 px. The lever opens the element as soon as it leaves its stop and the canvas clips the draw: 66 of 138 px with the lever at 48%.</li>
<li><b>A click on the summary can be cancelled.</b> With <code>preventDefault()</code> the element stayed closed, so the summary, by tap or by Enter, throws the lever and the lever opens the element.</li>
<li><b>A canvas-drawn part takes input through the canvas.</b> The knob isn't an element. A <code>pointerdown</code> whose target is the canvas, within 34 px of the knob, starts the drag, and a <code>touchstart</code> listener cancels the touch so that the page doesn't scroll (0 px of scroll in a scripted touch drag).</li>
<li><b>A turned figure is tapped where it is seen.</b> Under <code>ctx.rotate(0.5)</code> the corner of an image was found at its turned place, and the place it would have had with no turn gave the canvas.</li>
<li><b>A template has no box, and its clones are independent.</b> The template was 0 by 0 px with no client rectangles. Twelve clones were each found at their own place, and in the demo each of up to 18 tickets keeps its own tap count.</li>
<li><b>Buttons in a table are hit-tested through the table's picture.</b> 36 of 36 were found at their places. A disabled button is still what <code>elementFromPoint()</code> gives. One change to a button raised one paint event.</li>
<li><b>Not verified:</b> everything on a phone. Dragging the knob with a real finger, the long-press menu on a drawn image ("Save image"), the keyboard over the folder fields, and 38 px cells under a thumb.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/block-play.md">findings/block-play.md</a> in the repository.</p>
<p>Backlog group 28 in PLAN.md, ideas 28.4, 28.11, 28.22, 28.26 and 28.27. Measured in headless Chromium 157 (C157) on 2026-11-21 at 412 px wide. The page's five live checks pass there, and <code>node tools/block-play/check.mjs</code> drives the five demos by touch (33 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: can a 2D canvas turn block elements into things to pick up, pull and press while every tap still goes to the element?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Two fieldsets of 200 px, the first drawn at y 0 and the second at y 40</td><td>the tab button of the first is found at (40, 15); at (100, 110), in the overlap, the element is the input of the second</td><td>The element drawn last takes the input. Folder tabs from legends (28.4) draws three fieldsets from the back and changes the order on a tap.</td></tr>
<tr><td>A <code>legend</code> with <code>padding: 0</code> and a button in it</td><td>80 by 30 px, at the top of its fieldset; <code>margin-left</code> moves it</td><td>The tab. The fieldset has no border and no background, so only the body and the button are seen.</td></tr>
<tr><td>A tap on the text area of the front folder, and on a tab of a folder behind</td><td>the text area was focused; the order changed (Crew, Stores, Log to Log, Crew, Stores)</td><td>The back folders are also drawn with <code>ctx.filter = brightness()</code> and a smaller scale.</td></tr>
<tr><td>A closed <code>details</code></td><td>24 px tall, the height of its summary; its content reports 48 px</td><td>The content is not painted while closed, so it cannot be drawn part open. Open: 72 px.</td></tr>
<tr><td>A click on a <code>summary</code> with <code>preventDefault()</code></td><td><code>details.open</code> stayed false</td><td>Summary as a lever (28.27): the summary throws the lever, and the lever sets <code>open</code> and how much of the height is drawn.</td></tr>
<tr><td>A touch drag on the canvas-drawn knob (CDP touch events)</td><td>lever at 48% part way, <code>details.open</code> true, 66 of 138 px shown; 100% after release; page scroll 0 px</td><td><code>pointerdown</code> with the canvas as target, pointer capture, and a non-passive <code>touchstart</code> that cancels touches on the knob.</td></tr>
<tr><td>A figure drawn under <code>ctx.rotate(0.5)</code> about (150, 100)</td><td>the <code>img</code> is found at the turned place of its corner; the unturned place gives the canvas</td><td>Photo gallery with real alt text (28.11). The alt text is drawn by the canvas from the attribute (81 characters for the picked print).</td></tr>
<tr><td>A <code>template</code> as a canvas child, and 12 clones of its content</td><td>template 0 by 0 px, 0 client rectangles; 12 of 12 clones found at their places</td><td>Template stamped many times (28.22): up to 18 tickets in four layouts, each with its own tap count.</td></tr>
<tr><td>A 6 by 6 table of buttons, table drawable</td><td>36 of 36 found at their places; 1 paint event after one button changed; a disabled button is still what <code>elementFromPoint()</code> gives</td><td>Minesweeper from a table of buttons (28.26).</td></tr>
<tr><td>The first tap on the minefield</td><td>15 cells open after 0.12 s, 28 after 1.5 s (one run, the board is random)</td><td>Cells are opened 45 ms per cell of distance, each drawn enlarged for 0.25 s from a clipped draw of the table.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the five canvases and shows the elements as plain HTML (5 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The page first said that the content of a closed <code>details</code> has no box. The live check read 48 px for it. The element is short, and the content is not painted.</li>
<li>A text field in a folder overflowed the folder's body: a grid item has <code>min-width: auto</code>. The body's children now have <code>min-width: 0</code>.</li>
<li>The fan layout used a radius from the canvas height and put tickets off both sides at 412 px. The radius is now limited by the width.</li>
<li>A print's alt text was counted by hand as 80 characters and is 81.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the five demos by touch.</li>
<li>Dragging the knob with a real finger, and whether the page stays still while it is dragged.</li>
<li>The long-press menu on a drawn <code>img</code> ("Save image", "Open image in new tab").</li>
<li>A screen reader on the prints, the tickets and the minefield.</li>
<li>The on-screen keyboard over the folder fields.</li>
<li>38 px cells under a thumb, and a long press as the way to set a flag (the page uses a check box).</li></ul>
<p><a href="https://html-in-canvas.page/block-play/">Open Blocks to handle: legend, summary, figure, template and a table of buttons</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Which 2D operation loses the canvas</title>
<link>https://html-in-canvas.page/canvas-loss/</link>
<guid isPermaLink="true">https://html-in-canvas.page/canvas-loss/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>contextlost</category>
<category>drawElementImage</category>
<category>willReadFrequently</category>
<category>requestPaint</category>
<description>Twenty trials, each doing one thing that the pages which lost their canvases on a phone have in common. Each starts on a press. The result of every trial is stored before and after it runs, so a tab that dies names the trial that was running.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/canvas-loss/"><img src="https://html-in-canvas.page/canvas-loss/social.jpg" width="1200" height="630" alt="The page &quot;Which 2D operation loses the canvas&quot;"></a></p>
<p><strong>Question:</strong> Which single 2D canvas operation, run alone, loses the canvas or the tab on a phone?</p>
<p><strong>Short answer:</strong> On Chrome 159 for Android, a drawable 2D canvas made with <code>willReadFrequently</code>, drawn into and read once, lost every 2D canvas on the page every half second. Ten other operations did not. In Chromium 157 with software rendering no trial loses a canvas.</p>
<p>
Pages on this site that use only 2D canvases have lost their canvases, or the whole tab, on a phone (Chrome 159 on Android), and
not in the test browser. Each row below does one thing that those pages have in common, alone, for about four seconds. Press
"Run every trial" on the device that has the problem. It loads this page once for each trial, so that a trial which loses the canvases can't change the result of the next. If the tab dies, open this page again: the row that was running says so, and the run goes on with the next trial.
</p>
<h3>How it works</h3>
<ul>
<li>A trial builds its canvases in the box above, runs for about four seconds, removes them and gives them to <code>window.__gfx.retire()</code>. "Run every trial" then loads the page again for the next trial (<code>?run=&lt;id&gt;&amp;chain=1</code>): after a loss the guard stops <code>paint</code> events on a page, and a trial run after that would report the stop and not its own result.</li>
<li>Before a trial starts, its row is written to <code>localStorage</code> as "running". When it ends the row is written again with the outcome. A page load that finds a row still "running" reports that the tab stopped during that trial.</li>
<li>Every canvas of a trial has a <code>contextlost</code> listener. So has one plain 2D canvas that is made at load and never removed. Accelerated 2D canvases share one connection to the GPU process, so a trial that loses that connection loses this canvas too.</li>
<li>Each start and each outcome is also sent with <code>window.__gfx.report('trial', …)</code> to <code>/api/reports</code>, with the user agent. <code>npm run reports -- --type trial --list</code> prints them.</li>
<li>While trials run the page sets <code>window.__checkState</code> to "running", so the guard counts their readbacks as asked for.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Measured: no trial loses a canvas in the test browser.</strong> All twenty-one end with "no loss". That browser keeps canvases in ordinary memory, so this says the trials run, not that they're safe.</li>
<li><strong>Reported from Chrome 159 on Android 10, 2026-11-21: a <code>willReadFrequently</code> drawable canvas loses every 2D canvas.</strong> The ten trials before it ended with "no loss". The "read once" trial lost its own canvas and the canvas that stays, 35 ms after one draw and one readback, and again about every half second with no further call, until the guard stopped drawing. Live check fixtures across this site were made that way. <a href="https://html-in-canvas.page/crashes/repro/readback-matrix.html">A page with no site scripts</a> then showed, in a page load for each case, that the draw alone is enough and that reads without the option lose nothing.</li>
<li><strong>Fix: the guard removes the option.</strong> <code>/shared/context-guard.js</code> now takes <code>willReadFrequently</code> off a drawable canvas. Not verified on the phone: the two "guard" trials say whether that holds, and the readback, copy, snapshot and float trials haven't run there yet.</li>
<li><strong>Reported from the same phone, 2026-11-21: a second <code>getImageData()</code> on a drawable canvas loses every 2D canvas.</strong> The trial that reads one pixel every 300 ms from a drawable canvas in a paint loop lost its canvas and the canvas that stays 7 ms after the second read, and again after every second read. One read loses nothing. The guard now answers <code>getImageData()</code> on a drawable canvas from a <code>drawImage()</code> copy. </li>
<li><strong>Reported from the same phone at 20:20 UTC on 2026-11-21, a page load for each trial: both fixes hold.</strong> All 21 trials ran. 17 ended with no loss, including the three that go through the guard ("removed by the guard", "with the guard's fix", "sent through a copy by the guard"), twelve reads of a <code>drawImage()</code> copy, sixty open snapshots and the two float trials. The four that bypass the guard lost the canvases: twelve direct reads (12 losses), one <code>willReadFrequently</code> canvas (10), twelve such fixtures freed (11) and not freed (86).</li>
<li><strong>Limit: one operation at a time.</strong> A loss that needs two of these together, or more than four seconds, isn't found by this page.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/canvas-loss.md">findings/canvas-loss.md</a> in the repository.</p>
<p>Measured in C157 (headless, software rendering) on 2026-11-21, unless a row says otherwise. Nothing here has been run on A159.</p>
<h3>Why the page exists</h3>
<p>Pages with only 2D canvases lost their canvases or the tab on the test phone: <code>/instruments/</code>, <code>/scoped-transitions/</code>, and the five text pages of pull request 80. Their sizes are small (at most 9.7 MB and 1.7 megapixels, measured with <code>check:jank</code>), so the size budget does not explain it. The cause is not identified. <code>/canvas-loss/</code> runs one suspect at a time on the device that has the problem.</p>
<table><thead><tr><th>Trial</th><th>What it isolates</th><th>C157</th></tr></thead><tbody><tr><td><code>once</code></td><td>A drawable 2D canvas drawn once</td><td>no loss</td></tr>
<tr><td><code>loop</code></td><td><code>requestPaint()</code> on every frame</td><td>no loss</td></tr>
<tr><td><code>reset</code></td><td><code>ctx.reset()</code> in every paint</td><td>no loss</td></tr>
<tr><td><code>alpha0</code></td><td><code>drawElementImage()</code> at <code>globalAlpha</code> 0</td><td>no loss</td></tr>
<tr><td><code>shadow</code></td><td><code>shadowBlur</code> around the element</td><td>no loss</td></tr>
<tr><td><code>filter</code></td><td><code>ctx.filter</code> blur around the element</td><td>no loss</td></tr>
<tr><td><code>pieces</code></td><td>40 source-rectangle draws per paint</td><td>no loss</td></tr>
<tr><td><code>resize</code></td><td><code>canvas.width</code> assigned on every frame</td><td>no loss</td></tr>
<tr><td><code>twelve</code></td><td>12 drawable canvases painting at once</td><td>no loss</td></tr>
<tr><td><code>nested</code></td><td>A drawable canvas inside a drawable element</td><td>no loss</td></tr>
<tr><td><code>wrf</code></td><td>A <code>willReadFrequently</code> drawable canvas, read once</td><td>no loss</td></tr>
<tr><td><code>fixtures</code></td><td>12 check fixtures in a row, retired</td><td>no loss</td></tr>
<tr><td><code>fixtures-kept</code></td><td>12 check fixtures in a row, not retired</td><td>no loss</td></tr>
<tr><td><code>gpu-read</code></td><td><code>getImageData()</code> from an accelerated drawable canvas, 12 times</td><td>no loss</td></tr>
<tr><td><code>snapshots</code></td><td>60 <code>captureElementImage()</code> pictures never closed</td><td>no loss</td></tr>
<tr><td><code>float</code></td><td>One <code>getImageData()</code> with <code>pixelFormat: 'rgba-float16'</code></td><td>no loss</td></tr>
<tr><td><code>copy-read</code></td><td>Pixels read from a <code>drawImage()</code> copy in a plain <code>willReadFrequently</code> canvas, 12 times</td><td>no loss</td></tr>
<tr><td><code>wrf-guarded</code></td><td><code>willReadFrequently</code> asked for on a drawable canvas and removed by the guard</td><td>no loss</td></tr>
<tr><td><code>fixtures-guarded</code></td><td>12 check fixtures in a row with the guard's fix</td><td>no loss</td></tr>
<tr><td><code>float-copy</code></td><td>The float canvas copied with <code>drawImage()</code> to a <code>willReadFrequently</code> float16 canvas, and the copy read</td><td>no loss</td></tr></tbody></table>
<h3>Reported from the phone</h3>
<table><thead><tr><th>Page</th><th>Report (A159, 2026-11-21)</th></tr></thead><tbody><tr><td><code>/hdr-glow/</code> on production, after pull request 75 removed the timed readback</td><td>The page's own message: "The float16 canvas lost its context on this device (right after a float readback with getImageData(), 5.3 s after load)". The "Map of values above 1.0" option was selected, which reads the whole canvas as float pixels. So one float readback made by a tap is followed by the loss, as the timed ones were. Reported, one occurrence.</td></tr></tbody></table>
<p>| <code>/canvas-loss/</code> on production, "Run every trial", Chrome 159, Android 10 | <code>once</code>, <code>loop</code>, <code>reset</code>, <code>alpha0</code>, <code>shadow</code>, <code>filter</code>, <code>pieces</code>, <code>resize</code>, <code>twelve</code>, <code>nested</code>: no loss, 240 to 242 paints in 4 s each. <code>wrf</code>: "10 lost: the canvas that stays, a canvas of the trial at 35 ms, at 548 ms, at 1075 ms", pixel read 255,247,230,255. Guard log: "2 2D at 58.2 s after getImageData 1 px 9 ms before; 2 2D at 58.7 s; 2 2D at 59.2 s; 59.8 s; 60.3 s; 60.8 s. Drawing stopped by the guard." <code>fixtures</code>: "no loss, 0 had a drawn pixel" in the report log, which is not valid because the guard had stopped <code>paint</code> events. The pasted text said "TAB STOPPED" for it because it was copied while a trial was running; the tab did not stop. The rest are not valid for the same reason. The same rows arrived at <code>/api/reports</code> as type <code>trial</code>. |</p>
<p>Conclusion: a drawable 2D canvas made with <code>willReadFrequently: true</code>, after one <code>drawElementImage()</code> and one <code>getImageData()</code>, loses every 2D context on the page on that phone, and they are lost again every half second while it exists, with no further call from the page. Separated later by <code>/crashes/repro/readback-matrix.html</code> (A159, reported, 19:52 UTC, a page load for each case, no site scripts): <code>willReadFrequently</code> with <code>drawElementImage()</code> loses both canvases with or without a read (first loss 8 ms and 22 ms after the call, then about every 510 ms). Ten cases without the option lost nothing: draw only, <code>getImageData()</code> after <code>fillRect()</code> on a drawable and on a plain canvas, <code>getImageData()</code> right after <code>drawElementImage()</code> and 1 s later, a read from a <code>drawImage()</code> copy in a plain and in a <code>willReadFrequently</code> canvas, <code>toDataURL()</code>, <code>createImageBitmap()</code>, <code>captureElementImage()</code>. The guard now removes the option from drawable canvases. Trials added after this result: <code>copy-read</code>, <code>wrf-guarded</code>, <code>fixtures-guarded</code>. The three raw trials are left out of "Run every trial" and keep the option with <code>data-gfx-raw</code>.</p>
<h4>Second run on production, 20:03 UTC on 2026-11-21 (Chrome 159, Android 10)</h4>
<p>Reported through <code>/api/reports</code>, visit <code>0e3owys7mwqu4054</code>, with the guard of pull request 84. Ten trials (<code>once</code> to <code>nested</code>) ended with "no loss". <code>gpu-read</code> (a drawable canvas with no options in a paint loop, <code>getImageData()</code> of one pixel every 300 ms) ended "lost": 12 <code>contextlost</code> events, on the trial's canvas and on the canvas that stays, 7 ms after the second read, 3 ms after the fourth and 4 ms after the sixth, about 600 ms apart. 110 paints in 4 s where the other trials had 240. The guard stopped <code>paint</code> events after the third loss and the run ended there, so <code>copy-read</code>, <code>snapshots</code>, <code>wrf-guarded</code>, <code>fixtures-guarded</code> and the float trials have still not run on the phone.</p>
<p>Changes that follow from it: the guard answers <code>getImageData()</code> on a drawable canvas from a <code>drawImage()</code> copy; "Run every trial" loads the page once for each trial so that a loss cannot end the run; <code>gpu-read</code> keeps its direct read with <code>data-gfx-raw</code>, and <code>gpu-read-guarded</code> makes the same calls through the guard. In headless Chromium 157 all 21 trials end "no loss" in a chained run (measured 2026-11-21).</p>
<p>The run before it, at 20:01 UTC, was the page from before pull request 84 deployed: <code>wrf</code> lost 10 contexts, the first 6 ms after the read.</p>
<h4>Third run on production, 20:20 UTC on 2026-11-21 (Chrome 159, Android 10), a page load for each trial</h4>
<p>Reported through <code>/api/reports</code> with the guard of pull request 93. All 21 trials ran.</p>
<table><thead><tr><th>Trial</th><th>Result</th></tr></thead><tbody><tr><td><code>once</code>, <code>loop</code>, <code>reset</code>, <code>alpha0</code>, <code>shadow</code>, <code>filter</code>, <code>pieces</code>, <code>resize</code>, <code>twelve</code>, <code>nested</code></td><td>no loss, 240 to 242 paints in 4 s</td></tr>
<tr><td><code>gpu-read</code> (direct reads, guard bypassed)</td><td>lost: 12 events, first 5 ms after the second read, 109 paints</td></tr>
<tr><td><code>gpu-read-guarded</code> (the same calls through the guard)</td><td>no loss, 12 of 12 reads answered from a copy, 216 paints</td></tr>
<tr><td><code>copy-read</code></td><td>no loss, 12 copies read</td></tr>
<tr><td><code>snapshots</code></td><td>no loss, 60 pictures kept open</td></tr>
<tr><td><code>wrf-guarded</code>, <code>fixtures-guarded</code></td><td>no loss; the context reports <code>willReadFrequently</code> false; 12 of 12 fixtures had a drawn pixel</td></tr>
<tr><td><code>float-copy</code>, <code>float</code></td><td>no loss; read 1.00, 0.20, 0.10, 1.00</td></tr>
<tr><td><code>wrf</code> (guard bypassed)</td><td>lost: 10 events, first 9 ms after the read</td></tr>
<tr><td><code>fixtures</code> (guard bypassed, freed)</td><td>lost: 11 events, 6 of 12 fixtures had a drawn pixel</td></tr>
<tr><td><code>fixtures-kept</code> (guard bypassed, not freed)</td><td>lost: 86 events, 5 of 12 fixtures had a drawn pixel</td></tr></tbody></table>
<p>So both guard fixes hold on the phone, and one float16 read of a canvas that drew no element loses nothing there. The tab did not die in any trial. No <code>crash</code> or <code>tab-died</code> report arrived.</p>
<h3>Reports</h3>
<table><thead><tr><th>Question</th><th>Result</th></tr></thead><tbody><tr><td>Does <code>POST /api/reports</code> store a Reporting API batch (<code>application/reports+json</code>) and a guard beacon (<code>text/plain</code>)?</td><td>Measured with <code>wrangler dev</code> 4.166 and local D1: both answer 204 and the rows are returned by <code>GET /api/reports</code>. A report whose <code>url</code> is not a host of this project is dropped.</td></tr>
<tr><td>Are origins kept apart?</td><td>Measured locally: a report about a preview host and one about the production host are listed under separate origins by <code>npm run reports</code>.</td></tr>
<tr><td>Does the guard send a lost context, a script error, a rejected promise and a tab that died?</td><td>Measured in <code>tools/gfx/test-guard.mjs</code> against a local collector.</td></tr>
<tr><td>Does a page that died hold its drawing on the next load?</td><td>Measured with <code>Page.crash</code> in <code>tools/gfx/test-guard.mjs</code>: after the reload no <code>paint</code> event reaches the page until "Draw anyway" is pressed.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A preview is a static copy with no Worker, so <code>/api/reports</code> does not exist there. Every copy of the site posts to <code>https://html-in-canvas.page/api/reports</code>, and the row's origin comes from the report's own <code>url</code>.</li>
<li><code>navigator.sendBeacon()</code> with a <code>text/plain</code> Blob needs no CORS preflight. <code>application/json</code> does.</li>
<li>A report sent from a script in a page loaded by Playwright counts every <code>evaluate()</code> as a tap. The trials do not depend on that.</li></ul>
<h3>Not verified</h3>
<ul><li>On A159: the trials after <code>wrf</code> in the first run (<code>gpu-read</code>, <code>copy-read</code>, <code>snapshots</code>, <code>wrf-guarded</code>, <code>fixtures-guarded</code>, <code>float-copy</code>, <code>float</code>). Open <code>/canvas-loss/</code> on the phone and press "Run every trial". The results arrive at <code>/api/reports</code> as type <code>trial</code>.</li>
<li>That Chrome on Android sends a <code>crash</code> report (<code>reason: "oom"</code> or <code>"unresponsive"</code>) to <code>Reporting-Endpoints</code> for a tab that dies. To verify: after a white tab on the phone, <code>npm run reports -- --type crash --list</code>.</li>
<li>That <code>sessionStorage</code> and <code>localStorage</code> keep the last write when the renderer is killed on Android. The <code>tab-died</code> report and the "tab stopped" row depend on it.</li>
<li>That holding <code>paint</code> events after a crash keeps a crashing page alive on the phone. A page that dies from a WebGL or WebGPU frame loop is not stopped by it.</li>
<li>The live endpoint. It exists only after this change is deployed from <code>main</code>.</li></ul>
<p><a href="https://html-in-canvas.page/canvas-loss/">Open Which 2D operation loses the canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Captions drawn apart from the video</title>
<link>https://html-in-canvas.page/captions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/captions/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>TextTrack</category>
<category>activeCues</category>
<category>getCueAsHTML()</category>
<category>&lt;track&gt;</category>
<description>A video with a hidden text track. The page reads track.activeCues, builds each cue as HTML and the canvas draws it under the frame, as large text filled with the frame, or as a bubble at the cue's position. Words light up from the time stamps in the cue, and a tap on a word seeks to it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/captions/"><img src="https://html-in-canvas.page/captions/social.jpg" width="1200" height="630" alt="The page &quot;Captions drawn apart from the video&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw a video's captions as its own element, away from the frame, using only the text track API for the timing?</p>
<p><strong>Short answer:</strong> Yes. A hidden track keeps <code>activeCues</code> current and draws nothing, and <code>getCueAsHTML()</code> gives the voices and the time stamps inside a cue.</p>
<p>
The text track of this video is hidden, so the video draws no captions. The page reads <code>track.activeCues</code>, builds each cue as
HTML and the canvas draws that element by itself, away from the frame. Press Play, choose where the captions are drawn, and tap a word to
move the video to it.
</p>
<h3>How it works</h3>
<ul>
<li>A text track has three modes. In <code>hidden</code> the browser loads the file, keeps <code>activeCues</code> current and fires <code>cuechange</code>, and the video element draws nothing for it.</li>
<li><code>VTTCue.getCueAsHTML()</code> turns the cue text into nodes: <code>&lt;v Ada&gt;</code> becomes <code>&lt;span title="Ada"&gt;</code> and <code>&lt;00:00:01.626&gt;</code> becomes a <code>timestamp</code> processing instruction. <code>/lib/cue-layer.js</code> wraps each word in a <code>&lt;span&gt;</code> that carries the last time stamp before it.</li>
<li>The caption box is a second <code>drawable</code> child of the canvas. The paint handler chooses where it goes and at what size. The hit-test region follows the draw call, so a tap on a drawn word reaches its <code>&lt;span&gt;</code>, and the click handler sets <code>video.currentTime</code>.</li>
<li>In the mask mode the canvas clips to the caption area, draws the captions, sets <code>globalCompositeOperation = 'source-in'</code> and draws the video frame over the same area. The frame is kept only where the text is.</li>
<li>In the third mode the canvas reads <code>cue.position</code> and <code>cue.align</code> (set in the file as <code>position:4% align:start</code>) and puts the bubble on that side of the frame. It grows from 70% to full size over the first 0.2 s of the cue in media time.</li>
<li>The clip and its cue file are generated by <code>tools/speech-clip/make.mjs</code>. Cue times are measured. The word times inside a cue are estimates from the number of letters.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless with software video decoding, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: a hidden track gives the cues without drawing them.</strong> With <code>mode = 'hidden'</code> the video's picture in the canvas has no caption pixels, and <code>activeCues</code> and <code>cuechange</code> behave as they do for a shown track.</li>
<li><strong>Works: cues as HTML in a second drawable element.</strong> The caption element can be drawn under the frame, scaled, or over the frame, and its words take taps where they are drawn.</li>
<li><strong>Works: <code>getCueAsHTML()</code> keeps voices, classes and time stamps.</strong> The time stamps are <code>ProcessingInstruction</code> nodes with the target <code>timestamp</code>. Nothing else in the DOM exposes them.</li>
<li><strong>Measured: <code>cuechange</code> lateness.</strong> The fourth check reports how far the media time had moved past a cue's start when <code>cuechange</code> arrived. For a frame-exact result (an export, for example), compare <code>track.cues</code> with the frame's media time: <code>layer.update(time, { exact: true })</code> does that.</li>
<li><strong>Works: the frame as the fill of the text.</strong> <code>source-in</code> with a clip keeps the composite inside the caption area. The canvas background has to be CSS, because the area must be clear before the text is drawn.</li>
<li><strong>Limit: native caption styling isn't available to the page.</strong> <code>::cue(:past)</code> and <code>::cue(:future)</code> style the browser's own rendering, and that rendering stays inside the video's box. The elements here are styled with ordinary selectors.</li>
<li><strong>Not verified:</strong> a hardware-decoded video on Android as a direct <code>drawable</code> child, sound in step with the lit words on a real device, and a screen reader's reading of the caption box.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/captions.md">findings/captions.md</a> in the repository.</p>
<p>Measured in Chromium 157 headless (C157) with software video decoding, 2026-11-21. The clip is <code>public/media/talk.webm</code> with <code>talk.vtt</code>, made by <code>tools/speech-clip/make.mjs</code>: six sentences of synthesized speech, one cue each, a <code>&lt;v&gt;</code> voice per cue, a time stamp before each word and a <code>position</code> and <code>align</code> setting per speaker. Cue times are measured from the sound files. The word time stamps are estimates from letter counts.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>track.mode = 'hidden'</code> on a <code>&lt;track&gt;</code> with no <code>default</code> attribute</td><td>the file loads, <code>activeCues</code> follows the time, <code>cuechange</code> fires</td><td>After a seek to 8.0 s <code>activeCues</code> held cue 3 and one <code>cuechange</code> had fired.</td></tr>
<tr><td>The video's own picture with the track hidden</td><td>no caption pixels</td><td>0 bright grey pixels in the bottom third of the frame with the track hidden, more than 50 with it showing, same fixture.</td></tr>
<tr><td><code>VTTCue.getCueAsHTML()</code></td><td>keeps voices, classes, <code>&lt;b&gt;</code>, <code>&lt;i&gt;</code>, <code>&lt;lang&gt;</code>, <code>&lt;ruby&gt;</code> and time stamps</td><td><code>&lt;v Ben&gt;</code> becomes <code>&lt;span title="Ben"&gt;</code>, <code>&lt;c.loud&gt;</code> becomes <code>&lt;span class="loud"&gt;</code>, <code>&lt;00:00:07.008&gt;</code> becomes a <code>ProcessingInstruction</code> with target <code>timestamp</code>. Cue 3 gave 11 of them.</td></tr>
<tr><td>A caption element as a second <code>drawable</code> child, drawn under the frame</td><td>works</td><td><code>&lt;video drawable&gt;</code> and the caption <code>&lt;div drawable&gt;</code> are siblings in the canvas, one <code>drawElementImage()</code> call each.</td></tr>
<tr><td>Tap on a drawn word</td><td>reaches its <code>&lt;span&gt;</code></td><td><code>elementFromPoint()</code> at the drawn word returned the span, and its click handler set <code>currentTime</code> to the word's time stamp. Also done with the caption box scaled by the mask mode.</td></tr>
<tr><td>Words marked past, now and future from the time stamps</td><td>works</td><td>At 9.2 s cue 3 had 7 past words and "builds" current. The colour change is a CSS transition and raises <code>paint</code> with no <code>requestPaint()</code>.</td></tr>
<tr><td><code>cuechange</code> lateness during playback</td><td>1 ms of media time</td><td>Played across the start of cue 2 and read <code>currentTime</code> in the handler. One run, software decoding.</td></tr>
<tr><td>Captions as text filled with the video frame</td><td>works</td><td>Clip to the caption area, draw the caption element, set <code>globalCompositeOperation = 'source-in'</code>, <code>drawImage(video)</code> over the area. 2414 of 2781 text pixels took the frame's colours. The canvas background must come from CSS so the area is clear before the text is drawn.</td></tr>
<tr><td>Caption bubble placed from <code>cue.position</code> and <code>cue.align</code></td><td>works</td><td>The canvas reads the two settings and draws the element on that side of the frame, growing over the first 0.2 s of the cue in media time.</td></tr>
<tr><td><code>track.addCue(new VTTCue(...))</code> on the hidden track</td><td>shown like a cue from the file</td><td>Its <code>enter</code> event fired once and its element had the <code>&lt;b&gt;</code> from the cue text.</td></tr>
<tr><td><code>layer.update(time, { exact: true })</code>: cues chosen by comparing <code>track.cues</code> with a time</td><td>works</td><td>Needed when the time is ahead of what the browser has reached, as in a frame-by-frame export. Used by <code>/timed-comments/</code>.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A <code>&lt;track default&gt;</code> goes to <code>showing</code> by itself. The page leaves <code>default</code> off and sets <code>mode = 'hidden'</code>, which also starts the load.</li>
<li><code>details.checks-fold</code> is closed on a phone, so <code>innerText</code> of the result rows is empty. Test scripts should read <code>window.__results</code>.</li>
<li>The native caption text is small and anti-aliased. A check that counted pure white pixels found none. It now counts bright pixels with no colour, which the gradient picture of the clip does not have.</li>
<li>The caption area needs a height that does not depend on the caption. The canvas is <code>calc(56.25cqw + 198px)</code> tall inside a stage with <code>container-type: inline-size</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>A hardware-decoded <code>&lt;video drawable&gt;</code> as a direct canvas child on Android. Open <code>/captions/</code> on the phone and press Play: the frame should be in the canvas.</li>
<li>Whether the lit word matches the sound by ear. The test browser has no sound output, and the word times are estimates.</li>
<li><code>cuechange</code> lateness with a hardware decoder. The fourth live check reports it on the device.</li>
<li>A screen reader's reading of the caption box.</li></ul>
<h3>Open ideas</h3>
<ul><li>A second language track drawn beside the first, each in its own element.</li>
<li><code>kind="chapters"</code> cues as a drawn chapter list with the current chapter enlarged.</li>
<li>Region and <code>line</code> settings (<code>VTTRegion</code>) mapped to places outside the frame.</li></ul>
<p><a href="https://html-in-canvas.page/captions/">Open Captions drawn apart from the video</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Carets and highlights</title>
<link>https://html-in-canvas.page/caret/</link>
<guid isPermaLink="true">https://html-in-canvas.page/caret/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>caret-shape</category>
<category>caret-animation</category>
<category>highlightsFromPoint()</category>
<description>An editable block in a canvas with a CSS block caret, a streak the canvas draws behind the caret, wavy lines under misspelled words from a Custom Highlight, and highlightsFromPoint() to tap them.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/caret/"><img src="https://html-in-canvas.page/caret/social.jpg" width="1200" height="630" alt="The page &quot;Carets and highlights&quot;"></a></p>
<p><strong>Question:</strong> Is the CSS caret drawn into an element's picture, and can a canvas add effects to the caret and to Custom Highlight ranges in an editable element?</p>
<p>
An editable block drawn by a canvas. The browser draws the CSS caret into the picture. The canvas adds a streak behind it and wavy lines under misspelled words. Tap a marked word to correct it.
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.</p>
<ul>
<li><strong>The caret is in the element's picture</strong>, with its <code>caret-color</code> and <code>caret-shape</code>. The line under the editor counts its pixels in the canvas each time it moves.</li>
<li><strong><code>caret-animation: manual</code> stops the repaints.</strong> A blinking caret fires <code>paint</code> twice a second, and a shader effect uploads the element's texture each time. With <code>manual</code> the canvas is repainted only when the caret moves.</li>
<li><strong>The caret's position comes from a collapsed <code>Range</code>.</strong> <code>getClientRects()</code> returns one rectangle of zero width at the caret, at the drawn position. On an empty line it returns nothing, so the streak skips that move.</li>
<li><strong><code>CSS.highlights.highlightsFromPoint(x, y)</code> answers at the drawn position.</strong> It returns the Highlight and the range under the point, so a word that is only marked by a range can be tapped. No element wraps the word.</li>
<li><strong>A shader can find the caret without being told where it is.</strong> The key-glow effect has no rectangles. It samples the element's picture for the key colour, which the caret and the <code>::highlight()</code> underline both use. This also works for anything else painted in that colour, wanted or not.</li>
<li><strong><code>::highlight(*)</code> isn't in Chromium 157</strong> (it is listed for 158), so each named Highlight still needs its own rule.</li>
<li><strong>The marks are redrawn from ranges, so they survive editing.</strong> The typo list runs again on every <code>input</code> event and replaces the Highlight. A correction replaces the range's text with <code>Range.deleteContents()</code> and <code>insertNode()</code>.</li>
</ul>
<p><strong>Not built or not verified:</strong></p>
<ul>
<li><strong>Find-in-page and spelling marks in the picture:</strong> not verified here, see the button above.</li>
<li><strong>The Proofreader API</strong> (origin trial) isn't in the test browser. The typo list on this page stands in for it. The table above says whether your browser has it.</li>
<li><strong>Typing on an Android keyboard</strong>, with composition and autocorrect, wasn't tested.</li>
<li><strong>Not built:</strong> the editor on a 3D monitor (<a href="https://html-in-canvas.page/three-form/">the 3D form</a> has the surface), and a second editor using <code>EditContext</code> with the canvas drawing all the text.</li>
</ul>
<p><a href="https://html-in-canvas.page/caret/">Open Carets and highlights</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A CSS-only carousel drawn as a cover flow</title>
<link>https://html-in-canvas.page/carousel/</link>
<guid isPermaLink="true">https://html-in-canvas.page/carousel/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>scroll-snap</category>
<category>::scroll-marker</category>
<category>scroll-state()</category>
<category>texElementSubImage2D</category>
<description>A list with scroll snap, ::scroll-button() and ::scroll-marker, scrolled by no script. The canvas draws each card as a tilted quad with a reflection: cover flow, a wheel or a fan.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/carousel/"><img src="https://html-in-canvas.page/carousel/social.jpg" width="1200" height="630" alt="The page &quot;A CSS-only carousel drawn as a cover flow&quot;"></a></p>
<p><strong>Question:</strong> Can a carousel written in CSS only (scroll snap, generated buttons and markers) be drawn by a canvas as a 3D cover flow while the scroller keeps touch, keyboard and snapping?</p>
<p><strong>Short answer:</strong> Yes, with the cards positioned outside the scroller's clip. Drawable slides inside the scroller get clipped pictures, and scroll snap follows the drawn position of a slide, so the snap stops are left undrawn.</p>
<p>
The carousel below is a list with <code>scroll-snap-type</code>, <code>::scroll-button()</code> and <code>::scroll-marker</code>. No script scrolls it. It's a child of a canvas,
and the canvas draws each slide as its own textured quad, placed by how far the slide is from the centre of the scroller. Swipe it, use the two buttons or the dots (they are the
generated pseudo-elements, drawn by the canvas), or tab through the Save buttons.
</p>
<h3>How it works</h3>
<p>The scroller holds eight empty list items with <code>scroll-snap-align</code>; they're the snap stops and they generate the dots. Each item contains a card that is <code>drawable</code> and positioned against the deck, so it doesn't scroll and isn't clipped. The canvas uploads each card as its own texture and, on every <code>paint</code> event, draws the cards as quads whose position and rotation come from <code>scrollLeft</code>. The deck's own picture (background, the two buttons, the dots) is drawn first on a full-size quad. The canvas repaints on scroll, when a card's picture changes, and for one second after a snap.</p>
<h3>Findings</h3>
<ul>
<li>A <code>drawable</code> element nested inside another drawable element is left out of the outer element's picture and has a picture of its own. That's what lets the slides stay inside the
scroller: the deck's picture holds the background, the two buttons and the dots, and each card is uploaded separately (Chromium 157).</li>
<li>A drawable card that scrolls with the list gets a partial picture: the scroller clips it, and a card that is half out of the scroller's box is uploaded half empty. So each card is positioned against
the deck (<code>position: absolute</code>, with no positioned ancestor inside the scroller). It's still a descendant of its slide in the document, which keeps the <code>scroll-state()</code> query,
the tab order and the accessibility tree.</li>
<li>Scroll snap uses the place where an element is drawn. When the slides themselves were drawable and had hit boxes at their drawn positions, the scroller snapped to those positions, and a scroll to
slide 3 came to rest between two slides. The snap stops are therefore plain list items that the canvas doesn't draw.</li>
<li>Hit boxes that followed the tilted cards (<code>updateElementGeometry()</code> with a perspective matrix, or an affine one) worked for hit testing, but cards that had been outside the canvas were
drawn empty after they came back, until something else repainted them. Cards with a hit box that stays inside the canvas kept whole pictures. The cause isn't isolated. This page gives every card the
hit box of the centred position and lets only the snapped card's button take pointer events, with <code>pointer-events</code> set from the <code>scroll-state()</code> query.</li>
<li>A touch on a card scrolls the list because the card has <code>pointer-events: none</code> and the scroller is underneath it. Focusing a Save button doesn't scroll the list, because the card doesn't
move in layout; a <code>focusin</code> listener scrolls to the button's slide.</li>
<li><code>::scroll-button()</code> and <code>::scroll-marker</code> are in the deck's picture, and a tap where they are drawn works. They belong to the scroller, so they can't be drawn apart from the
deck without drawing the deck twice.</li>
<li>The <code>scroll-state(snapped: x)</code> query restyles the centred card with no script. Its transition changes the slide's picture, which raises <code>paint</code> for that slide only:
<code>changedElements</code> names the slides that need a new upload.</li>
<li>The canvas doesn't repaint on a timer. It paints when the list scrolls, when a card's picture changes, and for one second after a snap, while a highlight crosses the centred card.</li>
<li>Scrolling moves no pixels of any slide's picture, so a scroll alone doesn't always raise <code>paint</code>. The page calls <code>requestPaint()</code> from the scroller's <code>scroll</code> event.</li>
<li>Not verified here: touch fling on a phone. The test browser is driven by synthetic input.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/carousel.md">findings/carousel.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell) with synthetic touch, wheel, mouse and keyboard input. Not yet run on the test phone.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A <code>drawable</code> element nested inside another drawable element</td><td>own picture</td><td>It is left out of the outer element's picture, can be uploaded on its own with <code>texElementSubImage2D()</code>, and <code>updateElementGeometry()</code> accepts it.</td></tr>
<tr><td>Drawable slides that scroll with the list</td><td>clipped pictures</td><td>The scroller's clip applies to a nested drawable element. A slide that is half out of the scroller's box uploads half empty.</td></tr>
<tr><td>Scroll snap when slides have hit boxes at their drawn positions</td><td>snaps to the drawn positions</td><td>A scroll to slide 3 came to rest between two slides. Snap areas use the geometry given to <code>updateElementGeometry()</code>. The snap stops must be elements the canvas does not move.</td></tr>
<tr><td>Hit boxes that follow tilted cards out of the canvas</td><td>pictures go empty</td><td>Cards whose hit box had been outside the canvas were drawn empty after they came back, with a perspective matrix and with an affine one. With no geometry call, or a hit box that stays inside the canvas, the pictures stayed whole. Cause not isolated; worth a reduced test case.</td></tr>
<tr><td><code>::scroll-button()</code> and <code>::scroll-marker</code> drawn by the canvas</td><td>work</td><td>They are in the picture of the element that contains the scroller. A click or tap on the drawn button or dot scrolls the list. A full-width <code>::scroll-marker-group</code> laid over absolutely positioned buttons takes their clicks, in a canvas or out of one.</td></tr>
<tr><td><code>scroll-state(snapped: x)</code> on a slide whose card is drawn</td><td>works</td><td>It restyles the card, and <code>changedElements</code> then names that card only. The page also uses it to set <code>pointer-events</code> on the snapped card's button.</td></tr>
<tr><td><code>sibling-index()</code> in a custom property that a child uses</td><td>needs <code>@property</code></td><td>Unregistered, the function is resolved on the element that uses the value, so every card got index 1.</td></tr>
<tr><td>Touch swipe and wheel over a card</td><td>scroll the list</td><td>The cards have <code>pointer-events: none</code> and the scroller is under them.</td></tr></tbody></table>
<p>The layout that works: the snap stops are plain list items; each card is a <code>drawable</code> descendant of its stop, positioned against the deck so that it neither scrolls nor is clipped; the canvas computes each card's place from <code>scrollLeft</code>.</p>
<h3>Not verified</h3>
<ul><li>Chrome 159 on the test phone: touch fling, the generated buttons and dots under a finger, and speed. Opening <code>/carousel/</code> there and running its checks verifies the first two.</li>
<li>The cause of the empty pictures after a hit box leaves the canvas. A reduced page that moves one drawable child's geometry out of the canvas and back would isolate it.</li></ul>
<p><a href="https://html-in-canvas.page/carousel/">Open A CSS-only carousel drawn as a cover flow</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Cassette deck from audio controls</title>
<link>https://html-in-canvas.page/cassette/</link>
<guid isPermaLink="true">https://html-in-canvas.page/cassette/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>&lt;audio controls&gt;</category>
<category>::-webkit-media-controls</category>
<category>drawElementImage</category>
<category>AnalyserNode</category>
<description>One &lt;audio controls&gt; element fills a canvas. CSS lays its native parts out as a grid, and the canvas draws them piece by piece as the keys, counter and tape slider of a cassette deck. The reels turn with currentTime, and the browser's own play glyph is copied onto the cassette label.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/cassette/"><img src="https://html-in-canvas.page/cassette/social.jpg" width="1200" height="630" alt="The page &quot;Cassette deck from audio controls&quot;"></a></p>
<p><strong>Question:</strong> Can the native controls of an audio element be rearranged and drawn in pieces as another object, and stay the working controls?</p>
<p><strong>Short answer:</strong> Yes. The control panel accepts a CSS grid, a source rectangle draws one part at a time, and a final draw in an empty clip keeps taps on the native parts.</p>
<p>
The play key, the mute key, the counter and the tape position slider below are the native controls of one <code>&lt;audio controls&gt;</code>
element, laid out by CSS and drawn piece by piece by a canvas. The canvas adds the cassette, whose reels turn with <code>currentTime</code>.
Press the play key, drag the slider, and use Rewind and Forward.
</p>
<h3>How it works</h3>
<ul>
<li>The audio element is as large as the deck: 290 px tall and as wide as the canvas. A rule on <code>::-webkit-media-controls-panel</code> makes the panel a grid of four columns and four rows. The timeline is given the second row, the two time displays the third, and the play button and the mute button two cells of the fourth.</li>
<li>The canvas first draws the deck and the cassette with paths. Then it copies rows and cells out of the audio element with the nine-argument <code>drawElementImage(element, sx, sy, sw, sh, dx, dy, dw, dh)</code>. Each copy can have its own shadow, offset or scale.</li>
<li>The play button's glyph is the browser's. The canvas copies the centre of that cell onto the cassette label at twice the size, so the label shows a triangle while the tape is stopped and two bars while it plays, with no state code.</li>
<li>The pieces are drawn at the places the element's layout has them, so a tap on a drawn key is a tap on the native control. The last draw call restores the hit-test region to that layout.</li>
<li>The reels don't use a clock. The angle and the amount of tape on each reel are functions of <code>currentTime</code>, eased over a few frames, so dragging the slider winds the tape.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: the native controls can be laid out as a grid.</strong> <code>display: grid</code> on <code>::-webkit-media-controls-panel</code> and <code>grid-row</code> and <code>grid-column</code> on the named parts place the play button, the timeline, both time displays and the volume container. The first check finds the play button in the picture and compares its box with the grid cell.</li>
<li><strong>Works: pieces of one element drawn with different effects.</strong> A source rectangle selects a row or a cell. Shadow, offset and scale apply to each copy.</li>
<li><strong>Works: taps reach the native parts.</strong> A real touch on the drawn play key started playback, and a touch on the drawn timeline moved <code>currentTime</code> (tested with touch input from the test driver, which a live check can't produce).</li>
<li><strong>Found: the element drawn last is on top for hit tests.</strong> The audio element's region covers the whole deck. When its restoring draw came after the Rewind and Forward buttons were drawn, taps on those keys went to the audio element. Drawing the two buttons after it fixed that.</li>
<li><strong>Limit: one hit-test region per element.</strong> A piece drawn far from its layout position can't be tapped there. The region can only be the whole element under one transform, which is why the pieces stay near their layout places.</li>
<li><strong>Limit: internal parts.</strong> The overflow button has only the internal name <code>::-internal-media-controls-overflow-button</code>, which a page's CSS can't use, so it can't be given a grid cell. <code>controlslist="nodownload noplaybackrate"</code> empties its menu and the browser then leaves the button out.</li>
<li><strong>Works: <code>captureStream()</code> for the meters.</strong> The analyser reads the element's sound without taking over its output, so a suspended <code>AudioContext</code> costs the meters and not the sound.</li>
<li><strong>Not verified:</strong> the touch layout of the audio controls in Chrome 159 on Android (part sizes and which parts exist may differ, which the first check reports), sound output, and <code>audio.captureStream()</code> on Android.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/cassette.md">findings/cassette.md</a> in the repository.</p>
<p>Measured in Chromium 157 headless (C157), 2026-11-21, with emulated touch at 412 px. The sound is <code>public/cassette/tape.webm</code>, made by <code>tools/cassette/make.sh</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>display: grid</code> on <code>::-webkit-media-controls-panel</code> of an <code>&lt;audio controls&gt;</code> element</td><td>works</td><td>With <code>grid-row</code> and <code>grid-column</code> on the play button, the timeline, both time displays and the volume container. The play button filled its 80×72 cell exactly (found by filling it with magenta for one paint).</td></tr>
<tr><td>Size, font and colour on the parts</td><td>works</td><td>The current time display is drawn at 28 px in a monospace font. <code>filter: invert(1)</code> on the timeline makes the dark track light. <code>accent-color</code> on the timeline had no visible effect here.</td></tr>
<tr><td>An audio element 290 px tall</td><td>works</td><td><code>max-height: none; height: 100%</code> on <code>::-webkit-media-controls-enclosure</code> lets the panel fill it.</td></tr>
<tr><td>Pieces of the element with the nine-argument <code>drawElementImage()</code></td><td>works</td><td>Timeline row as laid out, counter row with a shadow glow, key cells 4 px lower while down, and the play glyph copied onto the cassette label at twice the size.</td></tr>
<tr><td>The browser's glyph as a state display</td><td>works</td><td>1482 label pixels changed on <code>play()</code> and 0 differed after <code>pause()</code>. No state code draws it.</td></tr>
<tr><td>Hit testing after the partial draws</td><td>right with the restoring draw</td><td>With a final full-size draw inside an empty clip, the play key, mute key and timeline answered <code>&lt;audio&gt;</code>. Without it all three answered the canvas.</td></tr>
<tr><td>Which element is on top for hits</td><td>the one drawn last</td><td>The audio element's box covers the deck. When its restoring draw came after the Rewind and Forward buttons, taps on them went to the audio element. Drawing the buttons afterwards fixed it.</td></tr>
<tr><td>Real touch on the drawn play key and timeline (test driver)</td><td>works</td><td>Playback started, the key was drawn down, the label showed the pause glyph, and a tap on the timeline moved <code>currentTime</code> to 19.1 s. A live check cannot produce trusted input, so this is not a row in the page's table.</td></tr>
<tr><td>Reels and counter from <code>currentTime</code></td><td>works</td><td>Tape pixels on the left reel went from 2775 at 6 s to 1060 at 18 s. The shown position eases towards <code>currentTime</code>, so a seek winds the reels.</td></tr>
<tr><td><code>AnalyserNode</code> on <code>audio.captureStream()</code></td><td>works</td><td>Levels read while the muted fixture kept playing. The element's own output is not rerouted, so a suspended <code>AudioContext</code> costs only the meters.</td></tr>
<tr><td>The overflow button</td><td>cannot be placed</td><td>Its only name is <code>::-internal-media-controls-overflow-button</code>. <code>controlslist="nodownload noplaybackrate"</code> empties its menu and the browser leaves the button out.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The timeline is 32 px wide in a grid cell until it is given <code>justify-self: stretch; width: auto; min-width: 0</code>.</li>
<li>An unplaced overflow button was put in the first free grid cell, over the cassette, where it took taps without being drawn.</li>
<li>The reels need frames while the tape plays. <code>paint</code> fires only about four times a second from the timeline's own repaint, so a <code>requestAnimationFrame</code> loop asks for paints while the audio is playing or the reels are still winding, and stops otherwise.</li></ul>
<h3>Not verified</h3>
<ul><li>The touch layout of audio controls in Chrome 159 on Android: part sizes, and whether the same parts exist. The first live check reports where the play button is.</li>
<li>Sound output, and <code>audio.captureStream()</code> on Android.</li>
<li>The volume slider is hidden. Mute is the only volume control on the deck.</li></ul>
<h3>Open ideas</h3>
<ul><li>A record key that captures the microphone into a second audio element.</li>
<li>Tape hiss, wow and flutter with an <code>AudioWorklet</code>, with the reels reading its speed.</li>
<li>The same deck for a <code>&lt;video&gt;</code>: the frame in the cassette window.</li></ul>
<p><a href="https://html-in-canvas.page/cassette/">Open Cassette deck from audio controls</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Plan: new platform features</title>
<link>https://html-in-canvas.page/chrome-apis/</link>
<guid isPermaLink="true">https://html-in-canvas.page/chrome-apis/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>chromestatus</category>
<category>plan</category>
<description>All 678 features that chromestatus.com lists for Chrome 130 to 160, each with a note on how it combines with a canvas that draws live DOM, and all 33 planned demos built from those notes.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/chrome-apis/"><img src="https://html-in-canvas.page/chrome-apis/social.jpg" width="1200" height="630" alt="The page &quot;Plan: new platform features&quot;"></a></p>
<p><strong>Question:</strong> Which features from Chrome 130 to 160 can be combined with a canvas that draws live DOM, and what happens when I build demos from them?</p>
<p><strong>Short answer:</strong> 359 of 678 features have an idea, 44 are measured by probes, and all 33 planned demos are built.</p>
<p>
Every feature that <a href="https://chromestatus.com/roadmap">chromestatus.com</a> lists for Chrome 130 to 160, with a note on how it combines
with a canvas that draws live DOM, and the demos built from those notes. Where a short test could settle a question it was run;
those rows are marked <i>measured</i>, and the tests are on the <a href="https://html-in-canvas.page/chrome-apis/probes.html">probes page</a>.
</p>
<h3>Findings</h3>
<ul>
<li>CSS that changes an element's outline or paint is applied in the element picture: <code>corner-shape</code>, <code>border-shape</code>, <code>clip-path: shape()</code>, gap decorations, <code>text-fit</code>, <code>caret-shape</code> and custom highlights were all measured.</li>
<li>Scroll-driven animations and <code>scroll-state()</code> queries inside a drawn element raise the canvas's <code>paint</code> event with no script. <code>streamAppendHTML()</code> raises one <code>paint</code> event per chunk.</li>
<li><code>::scroll-marker</code> and <code>::scroll-button()</code> pseudo-elements of a scroller in a canvas are drawn, and a real click on a drawn marker scrolls the list.</li>
<li>In Chromium 157 the browser tracks where an element is drawn: an element outside the canvas that is anchored to a canvas child follows the drawn position, an <code>interestfor</code> hint opens on hover at the drawn position, and <code>highlightsFromPoint()</code> and <code>OpaqueRange</code> rects use it. In Chromium 153 all four use the layout box.</li>
<li>A popover that is a descendant of a drawn element is not in its picture. It is shown in the top layer and hit tested there.</li>
<li>A float16 Display P3 canvas keeps a drawn element's wide-gamut colours and values above 1.0 (1.82 read back for an input of 4.0).</li>
<li>The browser protects two things from the canvas. Links are drawn as unvisited while the screen shows the <code>:visited</code> colour. Permission elements such as <code>&lt;geolocation&gt;</code> are drawn, and report <code>isValid</code> false with the reason <code>intersection_occluded_or_distorted</code>.</li>
<li>Not measured here: anything that needs a GPU, a headset, a sensor, a peripheral, an on-device model or a permission prompt. Those demos are in the hardware tier or name the requirement.</li>
</ul>
<p>The same content as one document: <a href="https://html-in-canvas.page/chrome-apis/plan.md">/chrome-apis/plan.md</a>. To change an idea, edit <code>tools/chrome-apis/ideas.json</code> and run <code>npm run build</code>.</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/chrome-apis.md">findings/chrome-apis.md</a> in the repository.</p>
<p><code>/chrome-apis/</code> lists the 678 features that chromestatus.com records for Chrome 130 to 160 with an idea for 359 of them and 33 planned demos (all 33 built as of 2026-11-22); the same content as one document is <code>/chrome-apis/plan.md</code> (<code>public/chrome-apis/plan.md</code> after <code>npm run build</code>). <code>/chrome-apis/probes.html</code> holds 27 probes, each of which draws one small element with one feature on and reads the result back. <code>npm run record:probes</code> runs them with real mouse and keyboard input in the two Chromium builds installed beside Playwright: the 157 headless shell and the 153 full browser with the <code>canvas-draw-element</code> flag.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>corner-shape</code>, <code>border-shape</code>, <code>clip-path: shape()</code>, gap decorations, <code>text-fit</code> on a drawn element</td><td>works</td><td>All are applied in the element picture; outlines arrive as alpha.</td></tr>
<tr><td><code>::scroll-marker</code> and <code>::scroll-button()</code> of a scroller inside a canvas</td><td>works</td><td>The pseudo-elements are in the picture, and a real click on a drawn marker scrolled the list.</td></tr>
<tr><td><code>scroll-state(stuck)</code> query, and a scroll-driven animation, inside a drawn element</td><td>works</td><td>Both restyle the element and raise <code>paint</code> with no <code>requestPaint()</code>.</td></tr>
<tr><td><code>streamAppendHTML()</code> into a drawn element</td><td>works (157)</td><td>One <code>paint</code> event per chunk. The method is missing in 153.</td></tr>
<tr><td>CSS <code>random()</code></td><td>stable (157)</td><td>The same value on two paints, so a per-element seed does not flicker. Missing in 153.</td></tr>
<tr><td>An element outside the canvas anchored to a canvas child</td><td>follows the drawn position in 157</td><td>Drawn at 100,50, the anchored element moved by 100,50. In 153 it stays at the layout box.</td></tr>
<tr><td><code>interestfor</code> on a drawn button</td><td>opens on hover in 157</td><td>Hover at the drawn position opened the hint. Failed in 153.</td></tr>
<tr><td><code>highlightsFromPoint()</code> and <code>OpaqueRange</code> rects on an element drawn away from its box</td><td>use the drawn position in 157</td><td>In 153 both use the layout box.</td></tr>
<tr><td><code>command</code> and <code>commandfor</code> on a drawn button</td><td>works</td><td>A click opened a popover that lives outside the canvas.</td></tr>
<tr><td>A popover that is a descendant of a drawn element</td><td>not in the picture</td><td>It is shown in the top layer at its own position and hit tested there.</td></tr>
<tr><td><code>focusgroup</code> arrow keys between drawn buttons</td><td>works</td><td></td></tr>
<tr><td><code>caret-shape: block</code> with <code>caret-animation: manual</code></td><td>works</td><td>215 caret pixels in the picture against 24 for a bar.</td></tr>
<tr><td><code>interactivity: inert</code> on a drawn element</td><td>works</td><td>Still drawn; <code>elementFromPoint()</code> skips it.</td></tr>
<tr><td>Element Timing for text and an image inside a canvas</td><td>reported</td><td>Entries carry <code>renderTime</code> and <code>presentationTime</code>.</td></tr>
<tr><td>Display P3 and values above 1.0 in a <code>float16</code> canvas</td><td>kept</td><td><code>color(display-p3 1 0 0)</code> read back as 1, 0, 0; <code>color(srgb-linear 4 4 4)</code> read back as 1.82.</td></tr>
<tr><td><code>:visited</code> colour in a picture that script can read</td><td>drawn as unvisited</td><td>Measured in 153 with a profile that keeps history: 921 visited-colour pixels on screen, 0 in the canvas.</td></tr>
<tr><td><code>&lt;geolocation&gt;</code>, <code>&lt;usermedia&gt;</code>, <code>&lt;camera&gt;</code>, <code>&lt;microphone&gt;</code> as canvas children</td><td>drawn, not valid</td><td><code>&lt;geolocation&gt;</code> reports <code>isValid</code> false, reason <code>intersection_occluded_or_distorted</code>.</td></tr></tbody></table>
<p>Things that bit:</p>
<ul><li>The two installed builds are different versions. The headless shell is 157 and behaves as if experimental web platform features were on; the full browser is 153 and needs the flag. Four results differ between them, and all four are about where the browser thinks a drawn element is. Chrome 159 on a phone has not been compared with either.</li>
<li>The headless shell keeps no history, so <code>:visited</code> never matches there. The probe reports that it could not tell, and the 153 run is the one that counts.</li>
<li>A fixture that sits below a 200 px <code>overflow: hidden</code> box is clipped out of screenshots. The comparison link for the <code>:visited</code> probe was invisible until the box was made taller.</li></ul>
<p><a href="https://html-in-canvas.page/chrome-apis/">Open Plan: new platform features</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Probes: new features on drawn elements</title>
<link>https://html-in-canvas.page/chrome-apis/probes</link>
<guid isPermaLink="true">https://html-in-canvas.page/chrome-apis/probes</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>getImageData</category>
<category>CSS</category>
<description>27 short tests of recent CSS and DOM features on elements that a canvas draws: carousels, anchor positioning, corner-shape, HDR colour, :visited, permission elements.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/chrome-apis/probes"><img src="https://html-in-canvas.page/chrome-apis/probes.social.jpg" width="1200" height="630" alt="The page &quot;Probes: new features on drawn elements&quot;"></a></p>
<p><strong>Question:</strong> Do recent CSS and DOM features take effect on an element that a canvas draws?</p>
<p><strong>Short answer:</strong> Shapes, carets, highlights, scroll markers and scroll-driven animations do. Popovers are not in the picture, links are drawn as unvisited, and permission elements report that they are distorted.</p>
<p>
Each probe puts a small element in a <code>&lt;canvas content="drawable"&gt;</code>, turns on one feature that shipped in Chrome 130 to 160,
draws the element with <code>drawElementImage()</code> and reads the pixels, the hit test or the element state back.
The results feed the <a href="https://html-in-canvas.page/chrome-apis/">plan for new platform features</a>.
</p>
<h3>Findings</h3>
<ul>
<li>The recorded column comes from <code>npm run record:probes</code>, which runs this page in two Chromium builds with real mouse and keyboard input and writes <code>/chrome-apis/probes-recorded.json</code>.</li>
<li>Three probes need a real pointer or key press (<code>::scroll-marker</code> click, <code>interestfor</code> hover, <code>focusgroup</code> arrow keys). The recording script supplies them. In a browser they report <i>manual</i>.</li>
<li>The <code>:visited</code> probe needs a browser profile that keeps history. The Chromium 153 run uses one and compares the picture with a screenshot of the same link outside the canvas.</li>
</ul>
<p><a href="https://html-in-canvas.page/chrome-apis/probes">Open Probes: new features on drawn elements</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Component kit: newer DOM features in a drawable element</title>
<link>https://html-in-canvas.page/component-kit/</link>
<guid isPermaLink="true">https://html-in-canvas.page/component-kit/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>custom element</category>
<category>scoped registry</category>
<category>Reference Target</category>
<category>Observable</category>
<category>moveBefore</category>
<description>A test element that draws a child in a canvas, written with a scoped registry, manual slot assignment, Reference Target, using, Observable and moveBefore(), and again without them. The page runs both and counts the lines.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/component-kit/"><img src="https://html-in-canvas.page/component-kit/social.jpg" width="1200" height="630" alt="The page &quot;Component kit: newer DOM features in a drawable element&quot;"></a></p>
<p><strong>Question:</strong> Do a scoped custom element registry, manual slot assignment, Reference Target, <code>using</code>, Observable and <code>moveBefore()</code> work in a custom element whose shadow root draws its children in a canvas, and how much code does each remove?</p>
<p><strong>Short answer:</strong> All six work in Chromium 157. Five remove code, most of it for labels and slots; <code>moveBefore()</code> adds lines and fixes what script could not: a wrapped iframe no longer reloads.</p>
<p>
I wanted to know whether six DOM features that shipped between Chrome 133 and 152 work in a custom element that draws its
children in a canvas, and what each one changes in the element's code.
</p>
<h3>Findings</h3>
<ul>
<li><strong>A scoped registry doesn't change how a canvas finds slotted children.</strong> An element defined only in a shadow root's own registry draws its slotted children, and <code>elementFromPoint()</code> on that shadow root returns them at the drawn position. Two classes can share the tag name <code>kit-slot</code> on one page.</li>
<li><strong>A manually assigned child is drawn, and an unassigned child has no box.</strong> The children carry no <code>slot</code> attribute. They still need the <code>drawable</code> attribute, which the element adds.</li>
<li><strong>Reference Target reaches a control that is a child of a canvas.</strong> A <code>&lt;label for&gt;</code> in the page focuses the input in the shadow root and is its accessible label. The target has to be inside the shadow root: an id of a slotted light-DOM child isn't found, so <code>&lt;kit-slot&gt;</code> can't use it for its children.</li>
<li><strong><code>ElementImage</code> has <code>close()</code> but no <code>[Symbol.dispose]</code>.</strong> <code>using image = canvas.captureElementImage(el)</code> throws a TypeError. It needs a wrapper object or <code>DisposableStack.adopt(image, (i) =&gt; i.close())</code>.</li>
<li><strong><code>using</code> is syntax, so it can't be feature-checked inside the file that uses it.</strong> The function that uses it is in its own module and is loaded with <code>import()</code> after <code>new Function()</code> has parsed a test statement.</li>
<li><strong><code>canvas.when('paint')</code> delivers the same events as <code>addEventListener</code>,</strong> in the same frame, and <code>take()</code>, <code>map()</code> and an AbortSignal work on them.</li>
<li><strong><code>moveBefore()</code> into a host whose shadow root slots the node into a canvas keeps focus and doesn't reload an iframe.</strong> The <code>fx</code> attribute, <code>&lt;dom-portal&gt;</code>, <code>&lt;dom-lens&gt;</code> and <code>&lt;physical-ui&gt;</code> now wrap elements this way where the method exists.</li>
<li><strong>Not tested here:</strong> <code>:has-slotted</code> isn't in the test browser (Chromium 157). The phone results for all six features are unknown until this page is opened there: the first table column reports them.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/component-kit.md">findings/component-kit.md</a> in the repository.</p>
<p>Tested in headless Chromium 157 at 1x, 1.5x and a phone profile. <code>&lt;kit-slot&gt;</code> and <code>&lt;kit-field&gt;</code> in <code>public/component-kit/kit.js</code> are written with each feature and with the code it replaces; the page runs both.</p>
<table><thead><tr><th>Feature</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Scoped <code>CustomElementRegistry</code> on the shadow root that holds the element</td><td>works</td><td>The element draws its slotted children and <code>elementFromPoint()</code> on that root returns them at the drawn position. A scoped registry does not change how the canvas finds slotted children. Two classes share one tag name on one page.</td></tr>
<tr><td><code>slotAssignment: 'manual'</code> with <code>slot.assign(child)</code></td><td>works</td><td>The assigned child is drawn. An unassigned child has no box, cannot take focus and needs no <code>slot</code> attribute. A child added later is not drawn until script assigns it.</td></tr>
<tr><td>Reference Target (<code>shadowRoot.referenceTarget</code>) for an input that is a canvas child</td><td>works</td><td>A <code>&lt;label for&gt;</code> in the page focuses the input and labels it. <code>label.control</code> is the host. The target must be inside the shadow root, so it cannot name a slotted light-DOM child.</td></tr>
<tr><td><code>using</code> with <code>ElementImage</code></td><td>needs a wrapper</td><td><code>ElementImage</code> has <code>close()</code> and no <code>[Symbol.dispose]</code>. <code>DisposableStack.adopt(image, (i) =&gt; i.close())</code> or a wrapper object closes it at the end of the block, at an early return and on a throw. Drawing a closed image throws <code>InvalidStateError</code>.</td></tr>
<tr><td><code>using</code> as a feature check</td><td>needs its own module</td><td>It is syntax, so the code that uses it is in <code>using.js</code> and loaded with <code>import()</code> after a parse test.</td></tr>
<tr><td><code>canvas.when('paint')</code> (Observable)</td><td>works</td><td>Same events as <code>addEventListener('paint')</code>. <code>map()</code>, <code>take()</code> and an AbortSignal work.</td></tr>
<tr><td><code>moveBefore()</code> into a host that slots the node into a canvas</td><td>works</td><td>Focus stays and an iframe inside does not reload. <code>replaceWith()</code> plus <code>append()</code> reloads the iframe once. <code>surface.js</code> (fx, dom-lens, physical-ui) and <code>dom-portal.js</code> now wrap with <code>moveBefore()</code> where it exists.</td></tr>
<tr><td><code>:has-slotted</code></td><td>not in Chromium 157</td><td>Not tested.</td></tr></tbody></table>
<p>Lines in the element, old code against new: registry 11 to 5, slots 15 to 6, label 15 to 1, closing snapshots 22 to 21, paint handlers 13 to 6. <code>moveBefore()</code> adds lines because the old path stays as the fallback. The page counts these from the running source.</p>
<p>Not confirmed on a phone: which of the six features Chrome 159 on Android reports, and whether the three small canvases on the page keep their contexts there.</p>
<p><a href="https://html-in-canvas.page/component-kit/">Open Component kit: newer DOM features in a drawable element</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Crashes and lost canvases recorded so far</title>
<link>https://html-in-canvas.page/crashes/</link>
<guid isPermaLink="true">https://html-in-canvas.page/crashes/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>contextlost</category>
<category>renderer crash</category>
<category>Reporting API</category>
<category>willReadFrequently</category>
<description>Every way a page of this project has crashed the tab or lost its canvases, one entry each: what was done, what happened, on which browser, how it was established, where to reproduce it and what the pages do now. Each entry copies as a bug report.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/crashes/"><img src="https://html-in-canvas.page/crashes/social.jpg" width="1200" height="630" alt="The page &quot;Crashes and lost canvases recorded so far&quot;"></a></p>
<p><strong>Question:</strong> Which calls crash the renderer or lose canvas contexts when HTML-in-canvas is used, and what is the evidence for each?</p>
<p><strong>Short answer:</strong> Thirteen entries on 2026-11-21, ten with a standalone reproduction page. Five of those pages crash headless Chromium 157 when their button is pressed. Two context losses were reported from Chrome 159 on Android with the call identified.</p>
<p>
Every way a page of this project has crashed the tab or lost its canvases while using HTML-in-canvas, one entry each. An entry
says what was done, what happened, in which browser, whether a script measured it or it was reported from a phone, where to
reproduce it, what is not known, and what the pages do now. "Copy as a report" gives one entry as plain text, with the number of
matching reports that real devices have sent.
</p>
<h3>How it works</h3>
<ul>
<li>The entries are written by hand in <code>/crashes/cases.js</code> from the findings of each page. Each says "measured" (a script or a page produced it, in the browser named) or "reported" (seen on my phone, with what came back).</li>
<li><code>/shared/context-guard.js</code> runs on every page. It sends each lost context, each stopped loop of losses, script errors and a tab that died to <code>/api/reports</code>. The browser sends its own <code>crash</code> reports there through the Reporting API. <code>/canvas-loss/</code> sends the outcome of each trial.</li>
<li>An entry names the report types that count towards it, with text the report must contain. The page asks the log for each and shows the total.</li>
<li>No reproduction runs here. Ten entries have a standalone page in <code>/crashes/repro/</code>: one HTML file with no libraries and none of this site's scripts (so the guard doesn't change what happens), with a button for each case and a log that is kept if the tab dies. Several of them crash the tab when the button is pressed.</li>
</ul>
<h3>Findings</h3>
<p>State on 2026-11-21. Headless Chromium 157 for "measured", Chrome 159 on Android for "reported".</p>
<ul>
<li><strong>Five renderer crashes reproduce in Chromium 157</strong> and involve a drawable canvas: a view transition on a drawable child, an iframe changed inside <code>paint</code>, <code>adoptNode()</code> of a painted canvas, opacity around a canvas in a drawn iframe, and <code>loseContext()</code> on a drawable WebGL canvas. Four have a standalone page that crashes there (the view transition, removing an iframe in <code>paint</code>, <code>adoptNode()</code>, the opacity box). The standalone page for <code>loseContext()</code> doesn't crash: that one needs something the fuller pages have.</li>
<li><strong>Two context losses on Chrome 159 for Android have their call identified:</strong> a drawable 2D canvas made with <code>willReadFrequently</code>, and a float16 <code>getImageData()</code>. Neither happens in the test browser. The first was isolated by <code>/canvas-loss/</code> on the phone; the second hasn't run alone yet. Their standalone pages haven't been opened on the phone.</li>
<li><strong>None has been filed.</strong></li>
<li><strong>Not verified:</strong> that Chrome on Android sends <code>crash</code> reports for a dead tab to this site. None had arrived when this was written.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/crashes.md">findings/crashes.md</a> in the repository.</p>
<p>State on 2026-11-21. "Measured" entries are from C157 (headless, software rendering). "Reported" entries are from A159 (Chrome 159 on Android, the project owner's phone).</p>
<p>The page is the list. Its entries are data in <code>public/crashes/cases.js</code>, one object each, and a new crash is added there. This file does not repeat them.</p>
<table><thead><tr><th>Question</th><th>Result</th></tr></thead><tbody><tr><td>How many entries?</td><td>13: 8 crashes of the tab or renderer (2 not related to HTML-in-canvas), 4 losses of canvas contexts, 1 blank canvas.</td></tr>
<tr><td>Which entries have a standalone page (<code>/crashes/repro/&lt;id&gt;.html</code>, one file, no libraries, no site scripts)?</td><td>Ten. Run in C157 on 2026-11-21 by pressing each button in a new browser:</td></tr>
<tr><td><code>view-transition-drawable-child</code></td><td>A crashes the renderer, B (child without the attribute) does not.</td></tr>
<tr><td><code>iframe-in-paint</code></td><td>B (remove an iframe child inside <code>paint</code>) crashes. A (insert) and C (after a timer) do not.</td></tr>
<tr><td><code>adopt-painted-canvas</code></td><td>A (painted first) crashes, B does not.</td></tr>
<tr><td><code>opacity-in-drawn-iframe</code></td><td>A (<code>opacity: .02</code>) crashes, B (<code>visibility: hidden</code>) does not.</td></tr>
<tr><td><code>speech-available</code></td><td>Crashes on the call.</td></tr>
<tr><td><code>lose-context-drawable</code></td><td>No crash with any button. The fuller pages that crashed have something this page lacks.</td></tr>
<tr><td><code>h264-software-encoder</code></td><td>30 chunks, no crash.</td></tr>
<tr><td><code>ninth-webgl-context</code></td><td>Context 1 is lost when context 17 is made (desktop limit).</td></tr>
<tr><td><code>frequent-read-drawable</code>, <code>float-readback</code></td><td>No loss in C157, as on every page there. Not opened on A159 yet.</td></tr>
<tr><td>Does the page count matching reports from devices?</td><td>Measured in C157 against the deployed log: each entry that names report types shows a count, with headless browsers left out (<code>real=1</code>).</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A report count must not include the test browser, which also sends reports. <code>/api/reports</code> takes <code>real=1</code>, which leaves out user agents that contain "Headless".</li></ul>
<h3>Not verified</h3>
<ul><li>Every "reported" entry on a second device.</li>
<li>The standalone pages for <code>frequent-read-drawable</code> and <code>float-readback</code> on A159. They run without the guard, so they show what the browser does with nothing removed.</li>
<li>That any entry is a browser bug and not intended behaviour. None has been filed.</li>
<li>That Chrome on Android sends <code>crash</code> reports for a dead tab to this site. None had arrived by 19:30 UTC on 2026-11-21.</li></ul>
<p><a href="https://html-in-canvas.page/crashes/">Open Crashes and lost canvases recorded so far</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Shader uniforms written in CSS only</title>
<link>https://html-in-canvas.page/css-uniforms/</link>
<guid isPermaLink="true">https://html-in-canvas.page/css-uniforms/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>@property</category>
<category>attr()</category>
<category>if()</category>
<category>sibling-index()</category>
<category>random()</category>
<category>@function</category>
<description>Twelve cards drawn through one fragment shader whose uniforms are registered custom properties. Each card shows the editable CSS rule that drives it: transitions, keyframes, typed attr(), sibling-index(), random(), if(), style queries, progress(), @function and a view timeline.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/css-uniforms/"><img src="https://html-in-canvas.page/css-uniforms/social.jpg" width="1200" height="630" alt="The page &quot;Shader uniforms written in CSS only&quot;"></a></p>
<p><strong>Question:</strong> Can a page drive every uniform of a canvas shader from CSS alone, and what does the canvas have to do to notice a change?</p>
<p><strong>Short answer:</strong> Every feature tried resolves to a number or colour in getComputedStyle(), including values in the middle of a transition or a view timeline. A custom property change raises no paint event, so the canvas reads the values once a frame; that read took about 0.1 ms for 12 cards.</p>
<p>
Twelve cards are drawn by one WebGL canvas through one fragment shader. The shader's uniforms are CSS custom properties: <code>uniform float uWave</code> reads <code>--u-wave</code> from each card.
Each card carries the CSS rule that sets its uniforms, in a <code>&lt;style&gt;</code> element that is displayed on the card. The rules use transitions, keyframes, typed <code>attr()</code>,
<code>sibling-index()</code>, <code>random()</code>, <code>if()</code>, style queries, <code>progress()</code>, <code>@function</code> and a view timeline. No card has script of its own.
Tap into a rule and change a number.
</p>
<h3>How it works</h3>
<p><code>lib/css-uniforms.js</code> reads the shader source, finds each <code>uniform float</code> and <code>uniform vec4</code>, and registers a custom property for it with
<code>CSS.registerProperty()</code>: a <code>&lt;number&gt;</code> for a float, a <code>&lt;color&gt;</code> for a vec4. A registered property has a type, so the browser can interpolate it in a transition,
an animation or a scroll timeline. Each card is a <code>drawable</code> element with its own texture. For each card the page reads the computed values with <code>getComputedStyle()</code> and sets them
as uniforms before drawing that card's quad.</p>
<p>A change to a custom property doesn't change the card's picture, so the browser raises no <code>paint</code> event for it. The page reads all values once per animation frame while the canvas is on
screen, compares the strings with the previous frame, and calls <code>requestPaint()</code> only when one differs. The line under the canvas shows what that read costs.</p>
<p>The rules on the cards are live <code>&lt;style&gt;</code> elements with <code>display: block</code> and <code>contenteditable</code>. Editing one changes the page's style sheet, and the next frame's read picks up the new value.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 every CSS feature on the cards produced a number or a colour that <code>getComputedStyle()</code> returns resolved: typed <code>attr()</code>, <code>sibling-index()</code>,
<code>random()</code>, <code>if()</code> with <code>style()</code>, a style range query, <code>progress()</code>, <code>@function</code>, and values in the middle of a transition, an animation or a view timeline.</li>
<li>Changing only a custom property raises no <code>paint</code> event, also when the property is registered and animating. The canvas has to poll. Reading 12 properties on 12 cards, with animations running on all of them, took about
0.9 ms per frame in the test browser, which includes resolving the animated values.</li>
<li>A registered <code>&lt;color&gt;</code> property in a transition is returned as <code>rgb()</code> or <code>rgba()</code> with interpolated components, so a colour uniform can be animated by CSS.</li>
<li><code>random()</code> keeps its value for an element across reads, so a seed doesn't flicker. It changes on reload.</li>
<li>A <code>&lt;style&gt;</code> element with <code>display: block</code> inside a drawn element is part of its picture, can be edited there with <code>contenteditable</code>, and its rules apply while it's edited.</li>
<li>A view timeline on a drawn card runs from the card's layout position in the page, so a card can form as it scrolls into the window.</li>
<li>Not verified: Chrome 159 on my phone, and the cost of the per-frame read there. The status line reports it.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/css-uniforms.md">findings/css-uniforms.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell, no experimental flags), 2026-11-21, at 412 pixels wide with synthetic touch and keyboard input. Not yet run on the test phone.</p>
<p><code>lib/css-uniforms.js</code> finds the <code>float</code> and <code>vec4</code> uniforms in a fragment shader's source, registers a custom property for each (<code>uRgbSplit</code> reads <code>--u-rgb-split</code>), reads them with <code>getComputedStyle()</code> and sets them on the program. The page draws twelve <code>drawable</code> cards with one WebGL context (<code>lib/element-gl.js</code>) and one shader.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A registered <code>&lt;number&gt;</code> property read in the middle of a transition</td><td>interpolated</td><td><code>--u-wave</code> from 0 to 10 over 600 ms read 6.11 at about 300 ms.</td></tr>
<tr><td>A registered <code>&lt;color&gt;</code> property in a transition</td><td>interpolated, returned as <code>rgb()</code></td><td>Red to blue read <code>rgb(99, 0, 156)</code> part way. With alpha it is <code>rgba()</code>. A <code>color-mix()</code> result is returned as <code>color(srgb r g b / a)</code>; the library parses both forms and sends any other form through a 2D canvas.</td></tr>
<tr><td>Typed <code>attr()</code>: <code>attr(data-split type(&lt;number&gt;), 0)</code></td><td>the number</td><td></td></tr>
<tr><td><code>sibling-index()</code> and <code>sibling-count()</code> in a registered property</td><td>per element</td><td>0.33, 0.67, 1.00 on three siblings. In <code>animation-delay</code> it staggers one animation across the cards.</td></tr>
<tr><td><code>random(0, 1)</code></td><td>one value per element, the same on every read, new on reload</td><td>So a seed uniform does not flicker.</td></tr>
<tr><td><code>if(style(--mode: crt): 1; else: 0)</code></td><td>picks the value</td><td>The result can be transitioned because the property is registered.</td></tr>
<tr><td><code>@container style(--level &gt;= 2)</code></td><td>applies</td><td>The container has to be an ancestor of the card. The demo sets <code>--level</code> on <code>main</code> with <code>:has(#hot:checked)</code>.</td></tr>
<tr><td><code>progress(100cqi, 100px, 500px)</code> in a 300 pixel container</td><td>0.5</td><td>Also inside <code>color-mix()</code> as a percentage.</td></tr>
<tr><td><code>@function --ease(--t &lt;number&gt;) returns &lt;number&gt;</code> called with <code>var(--u-phase)</code></td><td>computed, and follows <code>--u-phase</code> while it animates</td><td></td></tr>
<tr><td><code>animation-timeline: view()</code> on a card in the canvas</td><td>runs from the card's layout position in the page</td><td>The last card forms as it scrolls into the window. Seen in screenshots; no live check.</td></tr>
<tr><td>A change to a custom property alone (set from script, or a transition of a registered property)</td><td>no <code>paint</code> event</td><td>0 events after the set and 0 during the transition. The canvas has to poll or listen for transition and animation events.</td></tr>
<tr><td>Cost of polling: 12 elements, 12 properties, one value changed per read</td><td>0.094 ms</td><td>With animations running on all twelve cards the page's own counter shows 0.8 to 0.9 ms per frame, which includes resolving the animated values. Software rendering, so only the order of magnitude counts.</td></tr>
<tr><td>A <code>&lt;style&gt;</code> element with <code>display: block</code> inside a drawn card</td><td>drawn as text, editable with <code>contenteditable="plaintext-only"</code>, and its rules apply while it is edited</td><td>Typing 14 over 5 in <code>--u-wave: 5</code> on the card changed the uniform on the next frame.</td></tr>
<tr><td>Uploads while only uniforms change</td><td>none</td><td><code>changedElements</code> named each card twice during load (first paint and font load) and not again while the animations ran.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>&amp;lt;number&amp;gt;</code> inside a <code>&lt;style&gt;</code> element is not decoded, because <code>&lt;style&gt;</code> is raw text. The rule on the card has to contain a literal <code>&lt;number&gt;</code>.</li>
<li>A rule that sets <code>animation</code> on <code>.card</code> (the shared band of light) comes later in the document than some cards' own rules, so those cards use <code>.card.wave</code> to win on specificity.</li>
<li>A dissolve of 0.7 removed the card's own rule from view. The animation stops at 0.42.</li>
<li>The rules had to be reformatted to 25 characters a line to fit a card that is half of a 412 pixel screen.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on the test phone: every card, editing a rule with the on-screen keyboard, and the per-frame read cost. The status line under the canvas reports the cost.</li>
<li>Chromium 153: <code>random()</code>, typed <code>attr()</code>, <code>if()</code>, <code>sibling-index()</code> and <code>@function</code> are missing or partial there. The cards would draw with those uniforms at 0. Not run.</li>
<li><code>:hover</code> on touch. In the emulated touch run a tap did not leave <code>:hover</code> set, so the "Hover and press" card only bulges while pressed.</li>
<li>The canvas is 1448 CSS pixels tall on a phone. At a device pixel ratio of 2.625 that is a 3801 pixel buffer, under the common 4096 limit. A phone with a ratio above 2.8 would exceed it. To verify: open the page on such a phone.</li></ul>
<h3>Open ideas</h3>
<ul><li>Move the binding into <code>shader-fx.js</code> so that <code>fx="…"</code> effects take their uniforms the same way. That file belongs to the UI primitives strand, so it is not changed here.</li>
<li>Replace the per-frame poll with <code>transitionrun</code>, <code>animationstart</code> and a MutationObserver, and poll only while one of them is active.</li>
<li>A registered <code>&lt;custom-ident&gt;</code> property that selects the effect, so that the shader itself cascades.</li></ul>
<p><a href="https://html-in-canvas.page/css-uniforms/">Open Shader uniforms written in CSS only</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Datalist drawn by a canvas</title>
<link>https://html-in-canvas.page/datalist/</link>
<guid isPermaLink="true">https://html-in-canvas.page/datalist/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>datalist</category>
<category>drawElementImage</category>
<category>popover</category>
<category>anchor positioning</category>
<description>The suggestions of &lt;input list&gt; drawn one &lt;option&gt; at a time by a canvas in a popover, as a list or as pills that rearrange while you type. Also the options of a range input's datalist drawn as tick labels.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/datalist/"><img src="https://html-in-canvas.page/datalist/social.jpg" width="1200" height="630" alt="The page &quot;Datalist drawn by a canvas&quot;"></a></p>
<p><strong>Question:</strong> The popup of <code>&lt;input list&gt;</code> can't be styled. Can the <code>&lt;datalist&gt;</code> element itself be put in a canvas and its options drawn as the suggestions?</p>
<p><strong>Short answer:</strong> Yes, once the input's <code>list</code> attribute is removed and the keyboard handling is rewritten. An option in a datalist renders only text, so rich suggestions aren't possible this way.</p>
<p>
The suggestions of <code>&lt;input list&gt;</code> appear in a popup that the browser draws. It has no pseudo-element, it ignores CSS, and
it shows only each option's <code>value</code> and <code>label</code>. I wanted to know how much of a datalist a canvas can draw.
The built-in popup is out of reach, but the <code>&lt;datalist&gt;</code> element and its options are ordinary elements, so they can be
put in a canvas and drawn there.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The built-in datalist popup can't be drawn or styled.</strong> It isn't an element, it has no pseudo-element like <code>::picker(select)</code>, and <code>appearance: base-select</code> does nothing for it. Everything on this page works by replacing it.</li>
<li><strong>A <code>&lt;datalist&gt;</code> can be displayed and drawn.</strong> Its default style is <code>display: none</code>. With <code>display: block</code> inside a canvas, each <code>&lt;option drawable&gt;</code> in it can be passed to <code>drawElementImage()</code>, although the options are grandchildren of the canvas. Without the <code>drawable</code> attribute on the option the call throws.</li>
<li><strong>An option in a datalist shows only text.</strong> <code>&lt;option&gt;Leeds &lt;small&gt;LDS&lt;/small&gt;&lt;/option&gt;</code> parses and keeps the <code>&lt;small&gt;</code> in the DOM, but the option renders its label as plain text: the <code>&lt;small&gt;</code> has no box and <code>checkVisibility()</code> is false. Only options in a select with <code>appearance: base-select</code> render their children. <code>display</code> on the option also stays <code>block</code> whatever the page sets. <code>::before</code> and <code>::after</code> do render, so the hex codes and swatches above are pseudo-elements.</li>
<li><strong>The typed letters can't be marked inside an option.</strong> The CSS Custom Highlight API needs a range in rendered text. The text an option shows is in the browser's internal tree, not in the option's own text node, so a highlight on the text node paints nothing.</li>
<li><strong>Hit testing follows the drawing.</strong> <code>elementFromPoint()</code> at a drawn option returns that option, <code>:hover</code> applies, and a click reaches it. Options that are filtered out are moved away with <code>updateElementGeometry()</code>.</li>
<li><strong>Removing <code>list</code> removes everything the browser did.</strong> There is no way to keep the built-in keyboard handling and replace only the popup. Arrow keys, Enter, Escape, filtering and the <code>role="combobox"</code> wiring are rewritten in about 60 lines.</li>
<li><strong>An <code>&lt;option&gt;</code> in a datalist can't take focus.</strong> The active suggestion is tracked with <code>aria-activedescendant</code> on the input, and focus never leaves the input, so the on-screen keyboard stays open on a phone.</li>
<li><strong>A range input draws its ticks when it's drawn in a canvas.</strong> The tick marks from the datalist are part of the input's picture. The labels are extra elements drawn by the canvas at positions the page works out from <code>min</code>, <code>max</code> and the thumb width, because the input doesn't report where its ticks are.</li>
<li><strong>Not verified on real hardware.</strong> These results are from Chromium 157 driven by Playwright with a mouse and emulated touch. The built-in popup of the rotated input wasn't observed. The position of the suggestions above an on-screen keyboard is something I haven't tried on a phone.</li>
</ul>
<p><a href="https://html-in-canvas.page/datalist/">Open Datalist drawn by a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>17 ideas from the element catalogue, built</title>
<link>https://html-in-canvas.page/element-ideas/</link>
<guid isPermaLink="true">https://html-in-canvas.page/element-ideas/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawable descendants</category>
<category>drawElementImage</category>
<category>updateElementGeometry</category>
<description>A picker wheel from &lt;select multiple&gt;, a mixing desk from range inputs, a dialog with a drawn backdrop, a bar chart from table cells and 13 more. Each keeps the real element and says what the page had to add.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/element-ideas/"><img src="https://html-in-canvas.page/element-ideas/social.jpg" width="1200" height="630" alt="The page &quot;17 ideas from the element catalogue, built&quot;"></a></p>
<p><strong>Question:</strong> Can the ideas in the element catalogue be built with the real elements: a wheel of options, rotated range inputs, a dialog in the canvas, table cells as bars?</p>
<p><strong>Short answer:</strong> All 17 work. Options, list items and table cells can each be drawn on their own. A range input turned a quarter turn needs help with touch drags.</p>
<p>
The <a href="https://html-in-canvas.page/elements/">element catalogue</a> measures what each HTML element does inside a drawable canvas and lists things to build with it.
I built the first 17 of them on this page. Each one keeps the real element: the form control still holds the value, the link is still a link,
and the canvas only decides where and how the element is drawn. Under each demo is what the element still does without help and what the page had to add.
</p>
<h3>Findings</h3>
<ul>
<li><b>Any descendant with <code>drawable</code> can be drawn on its own, with its own hit region.</b> It doesn't have to be a child of the canvas, and its parent doesn't have to be drawn.
This works for <code>&lt;option&gt;</code> in a list box, <code>&lt;li&gt;</code> in <code>&lt;ul&gt;</code> and <code>&lt;menu&gt;</code>, and <code>&lt;td&gt;</code> in a table. The parent keeps its job: the select still owns the selection, the table cell is still a cell.
The wheel, the cover flow, the radial menu and the table chart are built on this.</li>
<li><b>Give <code>drawElementImage()</code> a size when the context is scaled by the device pixel ratio.</b> <code>drawElementImage(el, x, y)</code> draws the element at its size in device pixels. Under <code>ctx.scale(devicePixelRatio)</code> that is scaled a second time, so on a phone every element was three times too large until the calls became <code>drawElementImage(el, x, y, el.offsetWidth, el.offsetHeight)</code>.</li>
<li><b>A draw with <code>globalAlpha = 0</code>, or one that is clipped away completely, still moves the hit region.</b> The CRT terminal and the floor plan draw the element in distorted pieces and then make one invisible flat draw to say where input goes.</li>
<li><b>2D canvas transforms are affine, and so are the hit regions.</b> Rotation, shear and non-uniform scale all hit test correctly, including a range input turned a quarter turn and <code>&lt;area&gt;</code> shapes on a rotated, squashed image. A bend (the CRT bulge) has no matching hit region, so input uses the flat rectangle.</li>
<li><b><code>ctx.filter</code> and <code>globalCompositeOperation</code> apply to element pictures</b> like any other draw: blur for glow and for a dialog backdrop, <code>destination-in</code> with a dot pattern for the LED panel.</li>
<li><b>A range input drawn turned a quarter turn can't be dragged by touch.</b> Mouse drags and taps are mapped through the transform. Touch drags are tested for direction in screen space first, so a vertical drag on a horizontal slider is ignored. It also needs <code>touch-action: none</code>, or the drag scrolls the page. See <a href="https://html-in-canvas.page/element-ideas/#desk">Mixing desk</a>.</li>
<li><b>Don't move the hit region of a focusable element far away to hide it.</b> Focusing it then scrolls the page towards that place. <code>updateElementGeometry()</code> with a transform that shrinks it to a point inside the canvas avoids the scroll, and <code>inert</code> takes it out of the Tab order.</li>
<li><b><code>showPopover()</code> from script doesn't make the invoking button the anchor</b> unless it's passed as <code>source</code>. A tap on a <code>popovertarget</code> button does.</li>
<li><b>Not tested in the cloud browser:</b> the browser's own find-in-page scrolling the view in <a href="https://html-in-canvas.page/element-ideas/#find">Find and camera</a>, and whether Chrome on Android gives <code>&lt;select multiple&gt;</code> a list box to draw in <a href="https://html-in-canvas.page/element-ideas/#wheel">Picker wheel</a>.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/elements.md">findings/elements.md</a> in the repository.</p>
<h3>17 ideas from the catalogue, built (<code>/element-ideas/</code>)</h3>
<p>Each demo keeps the real element and draws it with a 2D canvas. Tested in headless Chromium 157 with mouse, keyboard and emulated touch (<code>npm run check:ideas</code>).</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td><code>drawable</code> on <code>&lt;option&gt;</code> in <code>&lt;select multiple&gt;</code>, <code>&lt;li&gt;</code> in <code>&lt;ul&gt;</code> and <code>&lt;menu&gt;</code>, <code>&lt;th&gt;</code> and <code>&lt;td&gt;</code> in a table</td><td>works</td><td>Each one is drawn on its own and has its own hit region. The parent is not drawn and keeps its job: the select owns the selection, the table lays out the cells.</td></tr>
<tr><td><code>drawElementImage(el, x, y)</code> with no size, under <code>ctx.scale(devicePixelRatio)</code></td><td>too large on a phone</td><td>With no size the picture is drawn at the element's size in device pixels, so the scale is applied twice: 3 times too large at a pixel ratio of 3, and the hit region with it. Correct at a ratio of 1, which is why the first tests passed. Pass the size in CSS pixels: <code>drawElementImage(el, x, y, el.offsetWidth, el.offsetHeight)</code>. Playwright's <code>deviceScaleFactor</code> does not show this, <code>--force-device-scale-factor</code> does.</td></tr>
<tr><td>A draw with <code>globalAlpha = 0</code>, or clipped away completely</td><td>moves the hit region</td><td>Used to say where input goes after the element was drawn in distorted pieces (CRT bulge, raised room).</td></tr>
<tr><td><code>&lt;input type="range"&gt;</code> drawn rotated 90 degrees, mouse drag</td><td>works</td><td>Up raises the value.</td></tr>
<tr><td>The same, touch drag</td><td>fails</td><td>A tap on the track is mapped through the rotation, a drag is not followed. A slider drawn at 17 degrees drags by touch. Chrome appears to test the drag's direction in screen space for a horizontal slider. The page sets the value from the pointer. Also needs <code>touch-action: none</code>.</td></tr>
<tr><td><code>&lt;area&gt;</code> on an image drawn rotated 45 degrees and scaled to half height</td><td>works</td><td>The click target is the area. Tab moves between areas.</td></tr>
<tr><td><code>&lt;dialog&gt;</code> opened with <code>show()</code>, drawn with a blurred page behind it</td><td>works</td><td>Needs <code>position: static</code>. The page adds <code>inert</code> on the content behind, Escape and focus return.</td></tr>
<tr><td><code>popover</code> anchored to a <code>popovertarget</code> button that the canvas moves each frame</td><td>works</td><td>The popover follows with no script. <code>showPopover()</code> from script needs <code>{ source: button }</code> or there is no anchor.</td></tr>
<tr><td>Hide an element by moving its hit region far away with <code>updateElementGeometry()</code>, then focus it</td><td>scrolls the page</td><td>The page scrolls towards the far place. Shrinking the region to a point inside the canvas does not.</td></tr>
<tr><td><code>ctx.filter</code> (blur, grayscale, brightness) and <code>globalCompositeOperation</code> (<code>lighter</code>, <code>destination-in</code>) on element pictures</td><td>work</td><td>Glow, dialog backdrop, LED dot mask.</td></tr>
<tr><td><code>getClientRects()</code> on <code>&lt;ins&gt;</code>, <code>&lt;del&gt;</code> and MathML tokens inside a drawn element</td><td>works</td><td>Boxes are in the drawn position, so differences between two boxes of one element are layout offsets.</td></tr>
<tr><td>A scroll container in the canvas, scrolled by script, then scrolled back and replayed as an animation</td><td>works</td><td><code>window.find()</code> in headless Chromium does not scroll a container, in or out of a canvas, so the page's own search form is what was tested.</td></tr>
<tr><td><code>&lt;video controls&gt;</code> drawn three times (blurred, mirrored, sheared)</td><td>works</td><td>Controls and captions are in every copy. The controls take clicks on the last copy drawn.</td></tr>
<tr><td><code>&lt;marquee&gt;</code> enlarged and masked</td><td>works</td><td>60 <code>paint</code> events a second with no timer. The link inside is hit on the enlarged picture.</td></tr></tbody></table>
<p>Not verified: the browser's find-in-page on <code>/element-ideas/#find</code>, whether Chrome on Android has a list box for <code>&lt;select multiple&gt;</code> (the wheel shows a message if the options have no boxes), and the touch-drag result on a real phone.</p>
<p><a href="https://html-in-canvas.page/element-ideas/">Open 17 ideas from the element catalogue, built</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Every HTML element in a canvas</title>
<link>https://html-in-canvas.page/elements/</link>
<guid isPermaLink="true">https://html-in-canvas.page/elements/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>elementsFromPoint</category>
<category>top layer</category>
<description>Each HTML element, input type and a few attributes, put inside a drawable canvas and measured: is it drawn, can it be hit, does it take real clicks and keys. With one thing to build for each.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/elements/"><img src="https://html-in-canvas.page/elements/social.jpg" width="1200" height="630" alt="The page &quot;Every HTML element in a canvas&quot;"></a></p>
<p><strong>Question:</strong> What does each HTML element do inside a drawable canvas: is it drawn, can it be hit, does it take input?</p>
<p><strong>Short answer:</strong> Every element with a box draws and hit tests. Top-layer content (modal dialogs, popovers, the base-select picker) stays outside the canvas, other origins are blank, and the picture is clipped to the element's box.</p>
<p>
What does each HTML element do as a child of <code>&lt;canvas content="drawable"&gt;</code>: is it drawn, can it be hit, does it take input?
Each row below is one element that was put in a canvas and measured, with one thing that could be built with it.
The measurements also decide which of the ideas further down are possible.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/elements.md">findings/elements.md</a> in the repository.</p>
<p>180 entries (each element in the HTML standard, each input type, a few attributes, some obsolete elements) put in a drawable canvas and measured in headless Chromium 157: drawn or not, share of the box with ink, what <code>elementsFromPoint()</code> returns at the drawn position, paint events with nothing touching the element, a screenshot compared with the same markup as plain DOM, and checks with real mouse and keyboard input. <code>ELEMENTS.md</code> has one row per element; <code>npm run record:elements</code> rewrites it and <code>public/elements/recorded.json</code>. 150 work, 4 work partly, 3 are blank, 22 have no box, 1 could not be measured (PDF).</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Any element that lays out a box: draw it, hit test it, click it</td><td>works</td><td>All sectioning, grouping, text-level, table and form elements, including <code>select multiple</code>, <code>details</code>, <code>iframe</code> (same origin), <code>svg</code>, <code>math</code>, <code>video</code> with native controls, a nested drawable canvas and custom elements with shadow trees.</td></tr>
<tr><td>Inline element or table part as the drawable child itself</td><td>draws as a block</td><td>The computed <code>display</code> of the drawable child is <code>block</code>. A <code>td</code> or <code>tr</code> drawn alone loses the table layout.</td></tr>
<tr><td>Content that overflows the drawn element (<code>dialog.show()</code> with the default <code>position: absolute</code>, overflowing <code>nobr</code> text, inline padding)</td><td>clipped</td><td>The picture is the element's box.</td></tr>
<tr><td><code>dialog.showModal()</code>, <code>[popover]</code>, the picker of <code>select</code> with <code>appearance: base-select</code></td><td>not in the canvas</td><td>They are in the top layer and the page paints them. <code>drawElementImage(dialog)</code> throws "No cached paint record".</td></tr>
<tr><td>CSS anchor positioning from a popover to an anchor drawn in a canvas</td><td>works</td><td>The popover sits against the drawn position of the anchor, and moves when the anchor is drawn 40 px away.</td></tr>
<tr><td>Base-select picker inside a canvas: click an option, or ArrowDown then Enter</td><td>fails</td><td><code>elementFromPoint()</code> at the option returns the canvas, and the keys leave the value unchanged (they work on the same select outside a canvas). The picker was painted under the drawn select in some runs and not in others.</td></tr>
<tr><td>Cross-origin <code>iframe</code>, cross-origin <code>img</code> without CORS, <code>object</code> with a <code>data:</code> document</td><td>blank</td><td>Excluded by read-back-allowed rendering.</td></tr>
<tr><td>Click the place where a blank cross-origin <code>iframe</code> is drawn</td><td>reaches the frame</td><td>The frame's button reported the click by <code>postMessage</code>. The frame is invisible and live.</td></tr>
<tr><td><code>geolocation</code> (permission element)</td><td>draws, refuses clicks</td><td><code>isValid</code> is false with <code>invalidReason</code> "intersection_occluded_or_distorted". Outside a canvas it is true.</td></tr>
<tr><td><code>video</code>, animated <code>img</code>, <code>marquee</code>, indeterminate <code>progress</code>, a focused <code>input</code></td><td>fire <code>paint</code> on their own</td><td>Each new frame or caret blink changes the element's picture. No <code>requestAnimationFrame</code> loop is needed while one of them is drawn.</td></tr>
<tr><td>Captions from <code>track</code></td><td>drawn with the video</td><td>The active cue is part of the video's picture.</td></tr>
<tr><td><code>area</code> in an image map</td><td>works</td><td>A click on the mapped part of the drawn image follows the link.</td></tr>
<tr><td><code>[inert]</code></td><td>works</td><td>A click on a drawn inert subtree goes to what is behind it. This is a fix for "undrawn children are still focusable".</td></tr>
<tr><td><code>[draggable]</code>, text selection by dragging, <code>textarea</code> resize handle, <code>input type=range</code> thumb, <code>input type=file</code> chooser</td><td>work</td><td>All at the drawn position.</td></tr>
<tr><td><code>script</code>, <code>style</code>, <code>title</code>, <code>head</code> with <code>display: block</code></td><td>draw their text</td><td>A <code>style</code> element with <code>contenteditable</code> can be edited in the canvas and its rules apply as you type.</td></tr>
<tr><td>Elements with no box (<code>datalist</code>, <code>template</code>, <code>slot</code>, <code>br</code>, <code>wbr</code>, <code>source</code>, <code>track</code>, <code>map</code>, <code>audio</code> without controls, metadata)</td><td>nothing to draw</td><td><code>drawElementImage()</code> throws "No cached paint record for element".</td></tr></tbody></table>
<p>Not measured, because headless Chromium does not show native popup windows: where the list of a plain <code>select</code>, the date, time and colour pickers, <code>datalist</code> suggestions and <code>title</code> tooltips appear when the element is drawn transformed. The PDF viewer is also missing there. <code>hidden=until-found</code> needs find-in-page driven by a person.</p>
<p>Two things the measurements had to work around. The page's stylesheet restyles test markup, so fixtures live in a shadow root. And a click on a new canvas at the spot where the pointer already rested did not focus the element under it until the pointer moved.</p>
<p><a href="https://html-in-canvas.page/elements/">Open Every HTML element in a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Flip clock from a time element</title>
<link>https://html-in-canvas.page/flip-clock/</link>
<guid isPermaLink="true">https://html-in-canvas.page/flip-clock/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>time</category>
<category>paint event</category>
<category>captureElementImage</category>
<category>@property</category>
<description>One &lt;time&gt; element whose text changes once a second. The canvas flips each changed digit from a snapshot of the old text to the new text. The frames of the flip come from a CSS animation on the element, so the page has no frame loop.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/flip-clock/"><img src="https://html-in-canvas.page/flip-clock/social.jpg" width="1200" height="630" alt="The page &quot;Flip clock from a time element&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas animation run on <code>paint</code> events alone, with no <code>requestAnimationFrame()</code> and no <code>requestPaint()</code>?</p>
<p><strong>Short answer:</strong> Yes. A text change fires <code>paint</code>, and an animation of a registered custom property fires it every frame when a painted colour is computed from the property. The property alone fires nothing.</p>
<p>
The clock is one <code>&lt;time&gt;</code> element drawn by a canvas. A timer changes its text once a second. Each change fires <code>paint</code>, and the canvas flips the digits that differ from a snapshot of
the old text to the new text. The page has no frame loop: the frames of a flip come from a CSS animation on the element. Change the time zone to flip most of the digits at once.
</p>
<h3>How it works</h3>
<p>A <code>setTimeout()</code> aimed at the start of each second formats the time and compares it with the element's text. When they differ it does three things: it calls <code>captureElementImage()</code> to keep a picture of
the element as it is, it sets the new text and the <code>datetime</code> attribute, and it starts a Web Animation that runs the registered custom property <code>--flip</code> from 0 to 1 in 520 ms.</p>
<p>The text change fires <code>paint</code>. The animation fires <code>paint</code> on every frame while it runs, because the element's top border has a colour computed from <code>--flip</code>. The paint handler reads
<code>--flip</code> with <code>getComputedStyle()</code> and uses it as the progress of the flip. For each digit that changed, the old face is a piece of the snapshot and the new face is a piece of the live element.
When the animation ends the paint events stop, and nothing runs until the next second.</p>
<p>The line under the controls counts the paint events and the calls the page made. <code>requestPaint()</code> is called when the canvas changes size and when it scrolls into the window, and not for the clock.</p>
<h3>Findings</h3>
<ul>
<li>Changing the text of a <code>&lt;time&gt;</code> element fires <code>paint</code>. A clock that shows seconds gets one paint event a second from the text alone.</li>
<li>An animation on a registered custom property fires no <code>paint</code> by itself. With a border colour computed from the property, <code>paint</code> fires once per frame of the animation, and
<code>getComputedStyle()</code> inside the handler returns the interpolated value. That gives a canvas an animation clock with no <code>requestAnimationFrame()</code> and no <code>requestPaint()</code>.</li>
<li>A CSS counter animated with <code>@keyframes</code> and shown through <code>content: counter()</code> fires <code>paint</code> for each new number. No script changes the text.</li>
<li><code>captureElementImage()</code> works in a timer, outside a paint handler, and returns the picture from the last paint.</li>
<li>Not verified: Chrome 159 for Android, and whether the timer and the animation keep in step when the phone throttles a page. Watch the status line for a minute: the paint count should rise by about 32 a second with seconds on.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/flip-clock.md">findings/flip-clock.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21, at 412 px wide with a device scale factor of 2 and at 1100 px wide. Not yet run on the test phone (Chrome 159 for Android).</p>
<p>Idea built: "Flip clock from a time element" from <code>public/elements/ideas.js</code> (rank 2, text).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Does changing the text of a <code>&lt;time&gt;</code> element fire <code>paint</code>?</td><td>measured: yes</td><td>1 paint event per change, <code>changedElements</code> holds the time element.</td></tr>
<tr><td>Does an animation of a registered custom property (<code>@property --flip</code>) fire <code>paint</code>?</td><td>measured: no</td><td>0 paint events in a 400 ms animation.</td></tr>
<tr><td>The same animation with <code>border-top-color: rgb(0 0 0 / calc(var(--flip) * 0.02))</code> on the element</td><td>measured: one paint event per frame</td><td>25 paint events in 400 ms. <code>getComputedStyle()</code> inside the handler returned an interpolated value in 23 of them. The colour change cannot be seen.</td></tr>
<tr><td>Can a flip animation run with no <code>requestAnimationFrame()</code> and no <code>requestPaint()</code>?</td><td>measured: yes</td><td>A fixture clock drew 33 paint events during one 520 ms flip and 0 in the 400 ms after it, with 0 calls to either function. On the page, 170 to 351 paint events in 10 seconds and 2 <code>requestPaint()</code> calls in total (canvas size, scrolling into the window).</td></tr>
<tr><td><code>captureElementImage()</code> in a timer, just before the text changes</td><td>measured: keeps the old digits</td><td>The last digit's box drew 667 pixels from the snapshot (4) and 575 from the live element (1).</td></tr>
<tr><td>An animated CSS counter shown with <code>content: counter()</code></td><td>measured: fires <code>paint</code> for each new number</td><td>7 paint events in 700 ms for a counter that steps 10 times a second. No script changes the text.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first version took a snapshot every second and never closed one. <code>ElementImage.close()</code> exists, and the clock now closes the previous snapshot before taking the next. Paul reported a crashed canvas on the phone before this change. Whether the unclosed snapshots were the cause is not verified.</li></ul>
<ul><li>A non-inherited registered property is not visible to the element's <code>::after</code>. A first test that used <code>--flip</code> for the opacity of a pseudo-element measured nothing, because the pseudo-element read the initial value. The test was removed.</li>
<li><code>fill: 'forwards'</code> keeps <code>--flip</code> at 1 after the animation, so the last paint draws the settled clock. Without it the value falls back to the initial value. The initial value is 1 for the same reason.</li>
<li>The old text is compared with the new text by index, so only the digits that differ flip. A time zone change flips most of them.</li>
<li><code>margin-right: -0.14em</code> on the digits takes off the letter spacing after the last digit, which would otherwise push the centred line to the left.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 for Android. Whether the timer and the animation stay in step when the browser throttles timers, and the paint count per second there. The status line reports it.</li>
<li>Battery cost against a <code>requestAnimationFrame()</code> loop. Not measurable in the test browser.</li>
<li><code>prefers-reduced-motion: reduce</code>: the code skips the animation, so the digits change without a flip. Not run.</li></ul>
<h3>Open ideas</h3>
<ul><li>A clock with no script: the digits from animated counters in generated content, with the flip progress from a second animation. The measurement above says the paint events would arrive.</li>
<li>The same paint-driven clock for a <code>&lt;progress&gt;</code> or <code>&lt;meter&gt;</code> whose value changes.</li></ul>
<p><a href="https://html-in-canvas.page/flip-clock/">Open Flip clock from a time element</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A DOM form inside a Flutter web app</title>
<link>https://html-in-canvas.page/flutter-dom/</link>
<guid isPermaLink="true">https://html-in-canvas.page/flutter-dom/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Flutter</category>
<category>drawElementImage</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>A Flutter app compiled for the web shows a real &lt;form&gt; as one of its widgets through createImageFromTextureSource(), and rotates, tilts and blurs it. Two designs: a second canvas over the view, and the form inside Flutter's own canvas.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/flutter-dom/"><img src="https://html-in-canvas.page/flutter-dom/social.jpg" width="1200" height="630" alt="The page &quot;A DOM form inside a Flutter web app&quot;"></a></p>
<p><strong>Question:</strong> Can a Flutter web app show a live DOM element as part of its own scene through dart:ui_web's createImageFromTextureSource(), with the browser still handling input on the element?</p>
<p><strong>Short answer:</strong> Yes. Flutter doesn't take an element or an ElementImage as a texture source, but it takes a 2D canvas that drew the element, and with the multi-surface rasterizer and one patched texImage2D() call it takes the element itself.</p>
<p>
Flutter draws every widget itself with CanvasKit, so a Flutter web app has no real inputs apart from one hidden text field.
This app shows a real <code>&lt;form&gt;</code> with an <code>&lt;input&gt;</code>, a <code>&lt;select&gt;</code> and a <code>&lt;textarea&gt;</code> as one of its widgets.
Flutter gets the form's pixels through <code>createImageFromTextureSource()</code> in <code>dart:ui_web</code> and rotates, tilts, fades and blurs them with its own widgets.
The browser still handles the form's input. Load the app, type in the form, then move the Flutter sliders.
</p>
<h3>How it works</h3>
<p>
<code>createImageFromTextureSource()</code> makes a <code>ui.Image</code> from an image, a video, a canvas, an <code>ImageBitmap</code> or a <code>VideoFrame</code>.
It doesn't take an element, so the page needs something that turns the form into one of those. Two designs do that here.
</p>
<ul>
<li>
<strong>A second canvas.</strong> The form is a child of a 2D canvas with <code>content="drawable"</code>. Each <code>paint</code> event draws the form with
<code>drawElementImage()</code>, and Flutter makes a new <code>ui.Image</code> from the canvas. The same canvas lies over the Flutter view with <code>opacity: 0</code>.
After each frame Flutter reports the widget's 4×4 matrix, and the page sets it as a CSS <code>matrix3d()</code> on the canvas, so the real fields are under the pointer where Flutter drew them.
This works with an unchanged Flutter engine.
</li>
<li>
<strong>The form inside Flutter's own canvas.</strong> With the engine option <code>canvasKitForceMultiSurfaceRasterizer</code>, CanvasKit renders into a WebGL canvas on the page.
The page sets <code>content="drawable"</code> on that canvas and moves the form into it. Flutter is given the form itself as the texture source.
CanvasKit uploads a source with <code>gl.texImage2D(…, source)</code>; the page replaces that one call with <code>texElementSubImage2D()</code>.
The matrix goes to <code>updateElementGeometry()</code>. There's no second canvas and no copy. The patch stands in for a change to the engine.
</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21 with software rendering, at 1× and at a 2.625 device scale with touch. Flutter 3.50.1, Dart 3.14.0.</p>
<ul>
<li><strong><code>createImageFromTextureSource()</code> doesn't take an element or an <code>ElementImage</code>.</strong> With <code>transferOwnership: false</code> the engine calls <code>createImageBitmap()</code> on the source, which throws a <code>TypeError</code> for both. With <code>transferOwnership: true</code> the call returns a <code>ui.Image</code> of the size it was told, and the error comes when the image is used: CanvasKit and Skwasm both upload lazily.</li>
<li><strong>It takes a 2D canvas that drew the element.</strong> A canvas with <code>content="drawable"</code> draws the form with <code>drawElementImage()</code> on each <code>paint</code> event, and Flutter makes a new <code>ui.Image</code> from it. The pixels read back from the image with <code>toByteData()</code> match the canvas. Flutter's <code>Transform</code> (with perspective), <code>Opacity</code> and <code>ImageFiltered</code> apply to the form, and a Flutter widget is drawn over it. This needs no change to Flutter. It worked the same with CanvasKit (dart2js) and with single-threaded Skwasm (dart2wasm).</li>
<li><strong>The copy is cheap next to Flutter's own frame.</strong> For a 924×572 px form image: <code>drawElementImage()</code> 0.1 ms; <code>createImageFromTextureSource()</code> 4 to 5 ms when the engine copies the canvas with <code>createImageBitmap()</code>, and 0.2 ms with <code>transferOwnership: true</code>, which hands CanvasKit the canvas itself. Flutter's raster time for the frame was 37 to 41 ms in every case, on a software renderer. The texture upload is inside the raster time and couldn't be separated. These numbers need a phone to mean anything: the page shows them live under the demo.</li>
<li><strong>Input works through the same canvas laid over the Flutter view.</strong> The canvas has <code>opacity: 0</code> and Flutter's 4×4 widget matrix as a CSS <code>matrix3d()</code>. Typing, the caret and the <code>&lt;select&gt;</code> by keyboard worked with the form rotated 38° and tilted 35° in perspective. Drag selection and Tab between the three fields worked at the starting angle. A click hands focus between Flutter's <code>TextField</code> and the DOM fields in both directions.</li>
<li><strong>Flutter's canvas is in a shadow root and, by default, isn't the canvas it renders into.</strong> The canvas inside <code>flt-glass-pane</code>'s shadow root has a <code>bitmaprenderer</code> context. CanvasKit renders into an <code>OffscreenCanvas</code> and transfers bitmaps. <code>content="drawable"</code> can be set on the visible canvas: a child of it gets <code>paint</code> events and <code>updateElementGeometry()</code> moves its hit box. Its pixels can't be used: a <code>bitmaprenderer</code> has no draw call for elements, and an <code>ElementImage</code> captured there is refused by every other canvas with "The source was captured from a different canvas".</li>
<li><strong>With the multi-surface rasterizer the form can live in Flutter's own canvas.</strong> The engine option <code>canvasKitForceMultiSurfaceRasterizer</code> (in the engine source, the mode chosen for Safari and Firefox) makes CanvasKit draw into a WebGL2 canvas on the page. The form is moved into it, Flutter is handed the form as the texture source, and CanvasKit's <code>gl.texImage2D(…, source)</code> is replaced by <code>texElementSubImage2D()</code> in a short patch. There's no second canvas and no copy: <code>createImageFromTextureSource()</code> took 0.2 ms and Flutter's raster 8 ms for the same form. The two raster times come from different rasterizers, so they don't measure the copy alone. The patch stands in for an engine change. Not tried with Skwasm.</li>
<li><strong><code>updateElementGeometry()</code> accepts a perspective matrix.</strong> In the in-canvas design Flutter's 4×4 matrix is passed as <code>canvasTransform</code>, and the three fields are hit tested correctly while rotated and tilted.</li>
<li><strong>Flutter takes focus back when focus moves inside its view.</strong> When Flutter's hidden text input loses focus to another element in the same <code>flutter-view</code>, the engine refocuses its input. With the form inside Flutter's canvas a click on a DOM field after using the Flutter <code>TextField</code> didn't move focus. The bridge blurs Flutter's input on <code>pointerdown</code> first, which closes Flutter's text connection.</li>
<li><strong>Flutter listens for keys on <code>window</code> in the capture phase.</strong> It sees every key typed into the form. With the form inside its view, Tab in the email field moved focus to the Flutter <code>TextField</code> instead of the next DOM field. The bridge adds its own capture listener before the engine starts and stops key events that come from the form.</li>
<li><strong>Flutter sets <code>pointer-events: none</code> on its scene.</strong> A form moved into Flutter's canvas inherits it and needs <code>pointer-events: auto</code>. Page stylesheets don't reach the shadow root, so the bridge adds the stylesheet there.</li>
<li><strong>The browser does not know what Flutter draws on top.</strong> The yellow badge is a Flutter widget over a corner of the form, and a pointer on the badge still goes to the form. The same was found for egui on <a href="https://html-in-canvas.page/native-ui/">/native-ui/</a>. Neither design here guards against it.</li>
<li><strong>Tab order is split.</strong> Tab walks the three DOM fields in DOM order and then leaves the form. Flutter's widgets aren't in that order.</li>
<li><strong>Not verified on a phone.</strong> Frame rates, the on-screen keyboard, IME composition, where the native <code>&lt;select&gt;</code> picker opens for a rotated form, and screen readers weren't tested. Multi-threaded Skwasm, which renders in a worker, wasn't tested either: the site isn't cross-origin isolated.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/flutter-dom.md">findings/flutter-dom.md</a> in the repository.</p>
<p>Measured in headless C157 on 2026-11-21, software rendering, at 1× (412 px and 1100 px wide) and at a 2.625 device scale with touch (<code>--force-device-scale-factor=2.625</code>, no emulation). Flutter 3.50.1 stable, Dart 3.14.0, <code>flutter build web --release</code>, dart2js, CanvasKit (Chromium variant) served from the site. Sources in <code>native/flutter-dom/</code>, build output in <code>public/flutter-dom/app/</code> (8.2 MB, largest file <code>canvaskit.wasm</code> 5.2 MiB). The page's live checks produce the rows marked "check". Rows marked "script" came from Playwright runs with a real mouse, touch and keyboard against <code>/flutter-dom/fixture.html</code>.</p>
<p>This is follow-up experiment 1 of <code>docs/native-frameworks.md</code>.</p>
<h3>What Flutter is on the page</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Renderer</td><td>CanvasKit (check)</td><td>Chosen in <code>flutter_bootstrap.js</code> with <code>renderer: 'canvaskit'</code> and <code>canvasKitVariant: 'chromium'</code>. A dart2wasm build with <code>renderer: 'skwasm'</code> was also run (script), not shipped.</td></tr>
<tr><td>Where Flutter's canvas is</td><td>In the shadow root of <code>flt-glass-pane</code>, inside <code>flutter-view</code> (check)</td><td><code>flutter-view &gt; flt-glass-pane #shadow-root &gt; flt-scene-host &gt; flt-scene &gt; flt-canvas-container &gt; canvas</code>. One canvas for this app. The shadow root is open.</td></tr>
<tr><td>What that canvas is, default rasterizer</td><td>A <code>bitmaprenderer</code> canvas (check)</td><td>CanvasKit renders into an <code>OffscreenCanvas</code> and transfers bitmaps to it. <code>getContext('webgl2')</code> on it returns null. Same with Skwasm (script).</td></tr>
<tr><td>What that canvas is, <code>canvasKitForceMultiSurfaceRasterizer: true</code></td><td>A WebGL2 canvas (check)</td><td>CanvasKit renders straight into the canvas on the page. In the engine source this rasterizer is chosen for Safari and Firefox. The option must be in the object passed to <code>initializeEngine()</code>; in the loader's <code>config</code> alone it had no effect when <code>onEntrypointLoaded</code> was used.</td></tr>
<tr><td><code>content="drawable"</code> on Flutter's canvas</td><td>Can be set in both modes (check)</td><td>Set after Flutter made its context. A child gets <code>paint</code> events and <code>getElementImageDefaultSize()</code> answers.</td></tr></tbody></table>
<h3>Route 1: the element, or an <code>ElementImage</code>, as the texture source</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td><code>createImageFromTextureSource(form, transferOwnership: false)</code></td><td>fails (check)</td><td>The engine calls <code>createImageBitmap(source)</code>: "TypeError: Failed to execute 'createImageBitmap' on 'Window': The provided value is not of type '(Blob or HTMLCanvasElement or …)'".</td></tr>
<tr><td><code>createImageFromTextureSource(form, transferOwnership: true)</code></td><td>fails when the image is used (check)</td><td>The call returns a <code>ui.Image</code> with the width and height it was given. <code>toByteData()</code> then fails with "Failed to execute 'drawImage' on 'CanvasRenderingContext2D'". Both renderers make the texture lazily.</td></tr>
<tr><td>The same two calls with <code>canvas.captureElementImage(form)</code></td><td>fail the same way (check)</td><td><code>createImageBitmap(ElementImage)</code> also throws when called from the page (script).</td></tr>
<tr><td>Same on Skwasm, single-threaded</td><td>fail the same way (script)</td><td></td></tr></tbody></table>
<h3>Route 2: a 2D canvas that drew the element</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Hidden <code>&lt;canvas content="drawable" layoutsubtree&gt;</code> with the form as a <code>drawable</code> child, <code>drawElementImage()</code> on each <code>paint</code>, canvas passed to <code>createImageFromTextureSource()</code></td><td>works (check)</td><td><code>toByteData()</code> on the image gives the canvas's centre pixel, rgba(16, 17, 20, 255).</td></tr>
<tr><td>Flutter shows the image in a <code>RawImage</code></td><td>works (check)</td><td>The form is painted magenta and rgba(255, 0, 255, 255) is read from Flutter's canvas at the widget's position.</td></tr>
<tr><td>Flutter <code>Transform</code> with perspective, <code>Opacity</code>, <code>ImageFiltered</code> blur, and a Flutter widget drawn over the form</td><td>work (script, screenshots)</td><td>The form is an ordinary widget in the tree.</td></tr>
<tr><td>Flutter sets the width, the browser answers with the height</td><td>works (script)</td><td><code>LayoutBuilder</code> calls <code>bridge.layout(width)</code>, which sets <code>form.style.width</code> and returns <code>offsetHeight</code>.</td></tr>
<tr><td><code>paint</code> events on a canvas with <code>opacity: 0</code></td><td>fire (check)</td><td>The canvas over the view is invisible and still painted.</td></tr>
<tr><td>Passing an <code>ImageBitmap</code> made by the page</td><td>works (check)</td><td><code>transferOwnership: true</code>.</td></tr>
<tr><td>Passing the canvas with <code>transferOwnership: true</code></td><td>works (check)</td><td>The engine skips <code>createImageBitmap()</code> and CanvasKit reads the canvas when it first draws the image.</td></tr>
<tr><td>Skwasm, single-threaded (dart2wasm, page not cross-origin isolated)</td><td>works (script)</td><td>Route 2 and the input test below gave the same results at 1×.</td></tr></tbody></table>
<p>Cost of one update. Means over 12 changes to the textarea, from the "cost" checks. Software renderer, so the absolute numbers say little about a phone.</p>
<table><thead><tr><th>Source</th><th>Image size</th><th><code>drawElementImage()</code></th><th><code>createImageBitmap()</code> by the page</th><th><code>createImageFromTextureSource()</code></th><th>Flutter raster per frame</th></tr></thead><tbody><tr><td>canvas, <code>transferOwnership: false</code></td><td>924×572 (2.625×)</td><td>0.10 ms</td><td></td><td>4.0 to 5.1 ms</td><td>39 to 41 ms</td></tr>
<tr><td>canvas, <code>transferOwnership: true</code></td><td>924×572</td><td>0.07 ms</td><td></td><td>0.2 ms</td><td>37 to 38 ms</td></tr>
<tr><td><code>ImageBitmap</code> from the page</td><td>924×572</td><td>0.09 ms</td><td>3.7 to 4.1 ms</td><td>0.2 ms</td><td>39 to 40 ms</td></tr>
<tr><td>canvas, <code>transferOwnership: false</code></td><td>352×219 (1×)</td><td>0.07 ms</td><td></td><td>0.9 to 1.1 ms</td><td>9 to 10 ms</td></tr>
<tr><td>canvas, <code>transferOwnership: true</code></td><td>352×219</td><td>0.09 ms</td><td></td><td>0.2 ms</td><td>9 to 11 ms</td></tr>
<tr><td><code>ImageBitmap</code> from the page</td><td>352×219</td><td>0.06 ms</td><td>0.8 to 0.9 ms</td><td>0.2 ms</td><td>10 to 14 ms</td></tr>
<tr><td>the form itself, in-canvas design</td><td>924×574</td><td>none</td><td>none</td><td>0.2 ms</td><td>8 ms</td></tr>
<tr><td>the form itself, in-canvas design</td><td>352×220</td><td>none</td><td>none</td><td>0.2 ms</td><td>2 ms</td></tr></tbody></table>
<p>The copy that can be measured is the <code>createImageBitmap()</code> call, 4 to 5 ms for a 924×572 image. The texture upload happens inside Flutter's raster and was not separated. The in-canvas rows use a different rasterizer (direct to the on-screen canvas instead of an <code>OffscreenCanvas</code> and a bitmap transfer), so the lower raster time is not the saving from the copy alone.</p>
<h3>Route 3: input</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>The source canvas laid over the Flutter view, <code>opacity: 0</code>, Flutter's <code>Matrix4</code> as CSS <code>matrix3d()</code></td><td>works (check, script)</td><td><code>RenderBox.getTransformTo(null)</code> after each frame. The 16 numbers are in the same order as <code>matrix3d()</code>. <code>elementFromPoint()</code> at the centre of each field returns that field with the form rotated 24° and tilted 32°.</td></tr>
<tr><td>Typing, caret, <code>&lt;select&gt;</code> by keyboard with the form rotated 38° and tilted 35°</td><td>works (script)</td><td>With a mouse at 1×. With touch taps at 2.625× the same was run at 18° and 28°, on the page itself, in both designs. Each keystroke gives a <code>paint</code> event and a new <code>ui.Image</code>.</td></tr>
<tr><td>Drag selection in the textarea, Tab between the three DOM fields</td><td>works (script)</td><td>At the starting angle of -4°.</td></tr>
<tr><td>Click from Flutter's <code>TextField</code> to a DOM field and back</td><td>works (script)</td><td>The canvas is outside <code>flutter-view</code>, so pointer events on it do not reach Flutter.</td></tr>
<tr><td>An element inside Flutter's <code>bitmaprenderer</code> canvas (default rasterizer): <code>paint</code> event, <code>updateElementGeometry()</code>, hit testing</td><td>works (check)</td><td>An <code>&lt;input&gt;</code> appended to Flutter's canvas, placed at 40, 20, is returned by <code>elementFromPoint()</code> there. It needs <code>pointer-events: auto</code>.</td></tr>
<tr><td>Getting that element's pixels to Flutter</td><td>fails (check)</td><td>A <code>bitmaprenderer</code> context has no element draw call. <code>captureElementImage()</code> returns an <code>ElementImage</code>, and <code>drawElementImage()</code> on a 2D canvas, on an <code>OffscreenCanvas</code> and <code>texElementSubImage2D()</code> on an <code>OffscreenCanvas</code> all throw "The source was captured from a different canvas".</td></tr>
<tr><td>A Flutter widget drawn over the form</td><td>does not block it (check, expected failure)</td><td><code>elementFromPoint()</code> on Flutter's yellow badge returns the form. Neither design guards against this.</td></tr></tbody></table>
<h3>The form inside Flutter's own canvas (the engine change, emulated)</h3>
<p>Open <code>/flutter-dom/?design=in-canvas</code>. The engine runs with <code>canvasKitForceMultiSurfaceRasterizer: true</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Move the form into Flutter's WebGL2 canvas and set <code>content="drawable"</code> on it</td><td>works (check)</td><td>The form needs <code>pointer-events: auto</code> (Flutter's scene has <code>pointer-events: none</code>) and a stylesheet inside the shadow root.</td></tr>
<tr><td><code>createImageFromTextureSource(form, transferOwnership: true)</code> with <code>gl.texImage2D(…, form)</code> replaced by an allocation and <code>gl.texElementSubImage2D(…, form)</code></td><td>works (check)</td><td>CanvasKit's lazy upload calls <code>texImage2D(TEXTURE_2D, 0, RGBA, w, h, 0, RGBA, UNSIGNED_BYTE, source)</code> on the context object, so an instance property replaces it. Magenta read back from Flutter's canvas. No 2D canvas, no <code>createImageBitmap()</code>.</td></tr>
<tr><td><code>updateElementGeometry(form, { canvasTransform })</code> with Flutter's 4×4 perspective matrix</td><td>works (check)</td><td>All three fields are hit tested correctly rotated 24° and tilted 32°. <code>canvasTransform</code> was in CSS px at 1× and at 2.625×.</td></tr>
<tr><td>Typing, <code>&lt;select&gt;</code> by keyboard, rotated and tilted</td><td>works (script)</td><td></td></tr>
<tr><td>Click on a DOM field after typing in Flutter's <code>TextField</code></td><td>fails without a workaround (script)</td><td>The engine's blur handler refocuses its hidden input when focus moves to an element in the same <code>flutter-view</code>. The bridge blurs the input on <code>pointerdown</code> first.</td></tr>
<tr><td>Tab in a DOM field</td><td>goes to Flutter without a workaround (script)</td><td>Flutter listens for <code>keydown</code> on <code>window</code> in the capture phase and moved its own focus to the <code>TextField</code>. A capture listener added before the engine starts stops key events that come from the form. After that Tab walks the DOM fields.</td></tr>
<tr><td>Skwasm</td><td>not tried</td><td>The patch is specific to CanvasKit's JavaScript.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>flutter build web</code> as root prints a warning and refuses to run git in the SDK folder until the folder is owned by the user that runs it (<code>chown -R</code>).</li>
<li>The engine fetches Roboto from <code>fonts.gstatic.com</code> unless the app bundles a family named Roboto. The app bundles two weights (344 KB).</li>
<li>Engine options given only to <code>_flutter.loader.load({ config })</code> did not reach the engine when <code>onEntrypointLoaded</code> called <code>initializeEngine({ hostElement })</code> with its own object. The same options have to be spread into that object.</li>
<li>Flutter makes its canvas during the first frame, after <code>runApp()</code> resolves. Code that looks for the canvas has to wait for it.</li>
<li>Material is a separate package (<code>material_ui</code>) in Flutter 3.50.</li>
<li>CanvasKit makes textures lazily. <code>createImageFromTextureSource()</code> returning an image proves nothing about the source. The checks read the image back with <code>toByteData()</code>.</li>
<li>A WebGL canvas with <code>preserveDrawingBuffer</code> off can be read with <code>drawImage()</code> only in the animation frame in which it was drawn. The check asks Flutter for a frame (it nudges the opacity control) and reads in a <code>requestAnimationFrame</code> callback registered after Flutter's.</li>
<li>In the in-canvas fixture the unused source canvas was still over the view and took the hit tests. It is set to <code>display: none</code> on adoption.</li>
<li>A canvas is blank between a resize and the next <code>paint</code> event. A readback taken in that gap gave rgba(0, 0, 0, 0).</li>
<li>The site serves at most 25 MiB per file. The build script keeps only <code>main.dart.js</code>, <code>flutter_bootstrap.js</code>, the Chromium CanvasKit, the fonts and the shader assets, and deletes the service worker, the full CanvasKit, Skwasm, the symbol files and <code>NOTICES</code>. The output is 8.2 MB.</li></ul>
<h3>Not verified</h3>
<ul><li>A real phone: frame rate with the copy on a GPU, the on-screen keyboard, IME composition, autofill, where the native <code>&lt;select&gt;</code> picker opens for a rotated form, touch selection handles. The page shows its timings live under the demo; open it on the phone and read them.</li>
<li>Screen readers: whether the form's fields are announced at the place Flutter drew them, in either design.</li>
<li>Multi-threaded Skwasm (needs a cross-origin isolated page, which this site is not). It renders in a worker, where an element cannot be touched; <code>docs/native-frameworks.md</code> item 5 describes the route to try.</li>
<li>The in-canvas design with Skwasm, and with more than one Flutter surface (platform views make Flutter split the scene over several canvases, and an element can be drawn only into its own).</li>
<li>WebGL context loss. The page listens for <code>webglcontextlost</code> and shows a message, and the listener was not exercised (<code>loseContext()</code> on an attached drawable WebGL canvas crashes the renderer in C157).</li>
<li>Firefox and Safari: the build ships only the Chromium variant of CanvasKit.</li>
<li>The separate cost of the texture upload inside Flutter's raster.</li></ul>
<h3>Requests for Flutter</h3>
<ul><li><code>createImageFromTextureSource()</code> (or a new call) that takes an element in the view's canvas and uploads it with <code>texElementSubImage2D()</code>. The patch in <code>public/flutter-dom/bridge.js</code> shows the one call that has to change in CanvasKit.</li>
<li>A place in the view for such elements. Today the engine takes focus back from any element inside <code>flutter-view</code> and handles keys typed into it.</li></ul>
<p><a href="https://html-in-canvas.page/flutter-dom/">Open A DOM form inside a Flutter web app</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Controller, keyboard and haptic navigation of drawn UI</title>
<link>https://html-in-canvas.page/focus-nav/</link>
<guid isPermaLink="true">https://html-in-canvas.page/focus-nav/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>focusgroup</category>
<category>Gamepad</category>
<category>focusVisible</category>
<category>vibrate</category>
<category>WebGPU</category>
<description>Buttons drawn through a shader, with focus moved by arrow keys (focusgroup), a game controller or an on-screen direction pad. The shader magnifies and lights the focused button and leans the panel toward it. Each move asks for a vibration.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/focus-nav/"><img src="https://html-in-canvas.page/focus-nav/social.jpg" width="1200" height="630" alt="The page &quot;Controller, keyboard and haptic navigation of drawn UI&quot;"></a></p>
<p><strong>Question:</strong> Can arrow keys, a game controller and an on-screen pad move DOM focus through buttons that a shader draws, and can the shader show where focus is?</p>
<p><strong>Short answer:</strong> In Chromium 157 focusgroup arrow keys move focus between drawn buttons along DOM order, a focus ring from focus({ focusVisible: true }) is in the texture, and taps reach the buttons while the panel leans. A real controller and phone vibration aren't verified.</p>
<p>
A panel of buttons drawn through a shader. Move focus with the arrow keys, a game controller, or the direction pad under the panel. The
shader magnifies and lights the focused button, takes the colour out of the rest, and leans the panel toward it. Each move asks for a
short vibration.
</p>
<h3>How it works</h3>
<p>
The panel is one drawable element, uploaded to a texture on every <code>paint</code> and drawn by a fragment shader
(<a href="https://html-in-canvas.page/lib/shader-fx.js"><code>fx</code></a>: WebGPU when it works, else WebGL). Focus is DOM focus on <code>&lt;button&gt;</code> elements. A
<code>focusin</code> listener writes the centre and size of the focused button into four CSS custom properties, CSS transitions move
them, and the shader reads them as uniforms. The effect also returns a matrix for the lean, which the library passes to
<code>updateElementGeometry()</code>, so a tap lands on the button that is drawn under the finger.
</p>
<p>
Three inputs move focus. Arrow keys go through the <code>focusgroup</code> attribute when the browser has it, which moves along DOM order,
or through the page's own function, which picks the nearest button in the direction pressed. A game controller and the direction pad
under the panel always use the page's function, because <code>focusgroup</code> answers only to keys. The controller is read by one
function, called from <code>rawgamepadinputchange</code> events when the browser has them and from a poll of
<code>navigator.getGamepads()</code> once per frame when it does not. The line under the demo says which of these this browser has, and
the log records what moved focus each time.
</p>
<h3>Findings</h3>
<ul>
<li><b>Measured, headless Chromium 157, 21 November 2026.</b> The key presses below were real key events sent by a test script, not the live checks, which can't send trusted keys.</li>
<li><b><code>focusgroup</code> arrow keys work on buttons drawn through a shader.</b> With <code>focusgroup="toolbar wrap"</code>, Right went Tides, Knots, Lights, Charts: along DOM order, past the end of the drawn row. Up and Down didn't move focus. Home and End went to the first and last button. Each group was one tab stop, and Shift+Tab into a group returned to the button it had last.</li>
<li><b>A grid needs the page's own function.</b> <code>focusgroup</code> moves along one axis, so it can't go to the tile below. The script route measures the buttons from layout and picks the nearest one in the direction pressed. It gave the expected button in six cases, including "nothing that way" at an edge.</li>
<li><b><code>reading-flow</code> changes where <code>focusgroup</code> and Tab go.</b> With the rows reversed by <code>order</code> and <code>reading-flow: grid-rows</code> on the grid, Right from Tides went to Journal and then Berths, which is the drawn order. With <code>reading-flow: normal</code> the same keys went Knots, Lights, which is DOM order and runs against the picture. Tab without <code>focusgroup</code> behaved the same way.</li>
<li><b><code>focus({ focusVisible: true })</code> makes a controller move show a ring, and the ring is in the texture.</b> The tile matched <code>:focus-visible</code> and 793 pixels of the outline colour were read back from the canvas. With <code>focusVisible: false</code> it didn't match and there were none.</li>
<li><b>The shader needs four numbers.</b> A <code>focusin</code> listener writes the centre and radius of the focused button into CSS custom properties, and transitions move them. The colour spread in the far corner of the picture fell from 53.6 to 8.7 when focus arrived.</li>
<li><b>Taps reach the buttons while the panel leans.</b> <code>elementFromPoint()</code> returned the right tile at the drawn centre of three tiles. A synthetic touch on a tile of the leaning panel in the demo pressed that tile.</li>
<li><b>The direction pad keeps focus in the panel.</b> Its buttons have <code>tabindex="-1"</code> and cancel <code>mousedown</code>, so a tap on them doesn't move focus. In the test each synthetic tap on the pad moved focus by one button, and <code>navigator.vibrate()</code> returned true.</li>
<li><b>Removing the <code>focusgroup</code> attribute logs a console error</b> ("focusgroup requires a recognized behavior token"). Setting it to <code>none</code> turns it off without the error.</li>
<li><b><code>rawgamepadinputchange</code> and <code>navigator.haptics</code> are missing in Chromium 157.</b> The page polls <code>getGamepads()</code> once per frame while a controller is connected. The controller path was run with plain objects shaped like a <code>Gamepad</code>: right, a held repeat, stick down and button 0 gave B, B, C, F and one press.</li>
<li><b>Not verified.</b> A real controller (its mapping, its <code>vibrationActuator</code>, and the event path where the origin trial is on), whether the phone vibrates and how a 12 ms pulse feels, a screen reader's announcement of each move, the direction pad under a real thumb, and WebGPU on screen. The line under the demo reports the controller and counts the vibrations the browser accepted.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/focus-nav.md">findings/focus-nav.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 on 2026-11-21. Key presses were real key events from a test script. No game controller was available.</p>
<table><thead><tr><th>What</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td><code>focusgroup="toolbar wrap"</code> on buttons drawn through a shader, ArrowRight</td><td>works</td><td>Focus went Tides, Knots, Lights, Charts: DOM order, past the end of the drawn row. Home and End work. One tab stop per group, and the group remembers its last button.</td></tr>
<tr><td>The same, ArrowDown and ArrowUp</td><td>no move</td><td>The toolbar behaviour moves on one axis. A grid needs the page's own function.</td></tr>
<tr><td>Rows reversed with <code>order</code>, <code>reading-flow: grid-rows</code></td><td>arrows and Tab follow the drawn order</td><td>Right from Tides went to Journal, then Berths. With <code>reading-flow: normal</code> it went Knots, Lights (DOM order).</td></tr>
<tr><td>Nearest button in a direction, from <code>offsetLeft</code> and <code>offsetTop</code></td><td>works</td><td>Six cases on a fixture, including "nothing that way". Unaffected by the lean, which changes <code>getBoundingClientRect()</code>.</td></tr>
<tr><td><code>focus({ focusVisible: true })</code> from script</td><td>matches <code>:focus-visible</code></td><td>793 outline pixels in the read-back picture; 0 with <code>focusVisible: false</code>.</td></tr>
<tr><td>The focus position given to a shader as four CSS custom properties</td><td>works</td><td>Colour spread far from the focus fell from 53.6 to 8.7. Transitions on the properties move the lit area.</td></tr>
<tr><td><code>elementFromPoint()</code> on the panel while it leans</td><td>works</td><td>Three tiles hit at their drawn centres.</td></tr>
<tr><td>A controller state read by one function</td><td>works with scripted states</td><td>Plain objects with the standard mapping: right, held repeat, stick down, button 0.</td></tr>
<tr><td><code>rawgamepadinputchange</code>, <code>navigator.haptics</code></td><td>missing</td><td>Chromium 157. The page polls <code>getGamepads()</code> once per frame while a controller is connected.</td></tr>
<tr><td><code>navigator.vibrate()</code> after a tap</td><td>returns true</td><td>Headless. Whether a phone vibrates is not verified.</td></tr>
<tr><td>Removing the <code>focusgroup</code> attribute</td><td>logs a console error</td><td>"focusgroup requires a recognized behavior token". <code>focusgroup="none"</code> turns it off without the error.</td></tr></tbody></table>
<p>Not verified: a real controller and its vibration, the gamepad event origin trial, vibration on the phone, a screen reader on each move, and WebGPU on screen.</p>
<p>What would verify it, on the test phone: use the direction pad and the A button and feel for the vibration, then connect a controller and read the line under the demo.</p>
<h3>Things that bit</h3>
<ul><li>A live check cannot send trusted key events, so <code>focusgroup</code> and <code>reading-flow</code> were measured with real keys from a test script. The page logs what each arrow key and Tab did, so the same can be read on a device.</li>
<li>Removing the <code>focusgroup</code> attribute logs "focusgroup requires a recognized behavior token". The page sets <code>focusgroup="none"</code> instead.</li></ul>
<p><a href="https://html-in-canvas.page/focus-nav/">Open Controller, keyboard and haptic navigation of drawn UI</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Focus order drawn as a path</title>
<link>https://html-in-canvas.page/focus-path/</link>
<guid isPermaLink="true">https://html-in-canvas.page/focus-path/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>tabindex</category>
<category>focus</category>
<category>getBoundingClientRect</category>
<category>inert</category>
<description>A canvas draws links, fields and buttons, and over them a numbered line through every Tab stop in the order the Tab key visits them. Steps that go against reading order are orange. Stops that aren't in the picture are listed in a red strip.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/focus-path/"><img src="https://html-in-canvas.page/focus-path/social.jpg" width="1200" height="630" alt="The page &quot;Focus order drawn as a path&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas work out the Tab order of the elements it draws and draw it over them, and does the path stay right when the picture is rearranged?</p>
<p><strong>Short answer:</strong> In Chromium 157 a rule of about 30 lines gave the same order as the real Tab key in the 5 arrangements tried. The positions come from getBoundingClientRect(), which follows the picture. An element that isn't drawn is still a Tab stop.</p>
<p>
The canvas draws three groups of links, fields and buttons. Over them it draws the order in which the Tab key visits them: a numbered
line from stop to stop. A step that goes against reading order is orange. Change the arrangement, give a button a
<code>tabindex</code>, or leave a group out of the picture, and the line is worked out again. Press Tab, or use the two buttons under
the picture, to move focus along it.
</p>
<h3>How it works</h3>
<ul>
<li>The order is worked out from the DOM. An element is a stop if its <code>tabIndex</code> is 0 or more, or it is an editing host, or it is a scroll container with nothing focusable inside. It's left out if it's disabled, inert, not rendered, or a radio button that isn't the checked one of its group. Stops with a positive <code>tabindex</code> come first, lowest first. The rest follow in tree order.</li>
<li>The position of each stop is its <code>getBoundingClientRect()</code>. For a child of a drawable canvas that is the box the element was last drawn in, so the line follows the picture when a group is drawn somewhere else or turned.</li>
<li>The page wraps <code>drawElementImage()</code> and keeps the list of elements drawn in the frame. A stop that isn't inside one of them isn't in the picture. Its number goes in the red strip at the bottom.</li>
<li>The path is drawn after the groups, in the same 2D context. The dashes move in the direction of travel unless the system asks for reduced motion.</li>
<li>"Previous stop" and "Next stop" call <code>focus({ focusVisible: true })</code> on the neighbouring stop of the path. They don't test the path. The Tab key does: the page notes each Tab press and compares the element that received focus with the next stop on the path.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: the order from the DOM matches the Tab key.</strong> A script pressed Tab through this page in six arrangements (the options above, and the details open) and the focused element was the next stop of the path every time. The script is <code>tools/devtools-pages/verify.mjs</code>.</li>
<li><strong>Limit: a positive <code>tabindex</code> is ordered in the whole document.</strong> With <code>tabindex="1"</code> on "Sign up", the path shows it as stop 1. That's its place among the stops of the canvas. In the page it is the first stop of the whole document, before the menu bar, and Tab doesn't reach it from the field before the canvas.</li>
<li><strong>Works: the path follows the picture.</strong> Drawing the groups in another order or at an angle moves the stops, because <code>getBoundingClientRect()</code> reports the drawn box. The Tab order doesn't change: it follows the DOM. "last group drawn first" shows the result, a path that starts at the bottom of the picture.</li>
<li><strong>Limit: under a rotation the reported box is the bounding box.</strong> The line still passes through the centre of each stop, since the centre of the bounding box of a turned rectangle is the centre of the rectangle. The outline round a stop is larger than the stop.</li>
<li><strong>Found: an element that isn't drawn is still a Tab stop.</strong> Tab moves focus to it and nothing in the picture shows where focus is. It also keeps the hit box of the last time it was drawn. Setting <code>inert</code> on it takes it out of the order. The "Last group" menu shows the three states.</li>
<li><strong>Found: <code>tabIndex</code> reads -1 for two kinds of Tab stop.</strong> An element with <code>contenteditable</code> and a scroll container with nothing focusable inside are both stops for the Tab key, and both report <code>tabIndex</code> -1. The rule checks for them separately.</li>
<li><strong>Not covered:</strong> shadow trees, slots, frames, <code>focusgroup</code> and <code>reading-flow</code> aren't followed by the rule. A <code>&lt;video controls&gt;</code> counts as one stop.</li>
<li><strong>Not verified here:</strong> a phone has no Tab key. The "next" key of the on-screen keyboard and a screen reader's swipe order weren't run. Connect a keyboard to the phone and press Tab: the status line counts how many presses matched the path.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/focus-path.md">findings/focus-path.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21. Tab presses were real key events from <code>node tools/devtools-pages/verify.mjs</code>. The other rows are the page's live checks.</p>
<table><thead><tr><th>What</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Tab order worked out from the DOM against the real Tab key</td><td>agrees</td><td>Six arrangements of the page (as in the document, last group drawn first, turned with <code>tabindex="1"</code>, last group not drawn, last group inert with a disabled field, details open), 9 to 15 stops each. Every press landed on the next stop of the drawn path.</td></tr>
<tr><td>Positive <code>tabindex</code>, then tree order</td><td>works</td><td>Five stops in a fixture: order <code>d b a c e</code>.</td></tr>
<tr><td>Elements that Tab skips</td><td>left out</td><td>Disabled, inside <code>inert</code>, <code>tabindex="-1"</code>, <code>type="hidden"</code>, <code>display: none</code>, <code>visibility: hidden</code>, a link in a closed <code>&lt;details&gt;</code>, an unchecked radio button.</td></tr>
<tr><td><code>tabIndex</code> of an editing host and of a scroll container with nothing focusable inside</td><td>-1, and both are Tab stops</td><td>The rule tests for them separately.</td></tr>
<tr><td>Position of a stop</td><td>the drawn box</td><td><code>getBoundingClientRect()</code> gave 150, 90 for a button laid out at 0, 0 and drawn at 150, 90.</td></tr>
<tr><td>Position under a draw turned 30 degrees</td><td>bounding box, same centre</td><td>An 80 by 30 button reports 84 by 66. The centre is the centre of the button.</td></tr>
<tr><td>A child of the canvas that is not drawn</td><td>still a Tab stop</td><td>Tab moved focus to all four stops of a group that was not drawn. The page lists them in a strip.</td></tr>
<tr><td><code>inert</code> on the group that is not drawn</td><td>removes its stops</td><td>14 stops became 9 (with the disabled field).</td></tr>
<tr><td>Opening a <code>&lt;details&gt;</code></td><td>adds the stops inside</td><td>The path is worked out again from a <code>toggle</code> listener and a MutationObserver.</td></tr>
<tr><td>A positive <code>tabindex</code> inside the canvas</td><td>first in the whole document</td><td>Tab from the top of the page went to "Sign up" before the menu bar. Tab from the element before the canvas skipped it.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>tabIndex &gt;= 0</code> is not the whole rule. <code>contenteditable</code> elements and keyboard-scrollable containers report -1.</li>
<li>Positive <code>tabindex</code> values are ordered across the document, not inside the canvas. The first version of the Tab comparison started just before the canvas and never reached the element.</li>
<li>Under a rotation the outline round a stop is its bounding box. <code>getBoxQuads()</code> does not exist in Chromium, so the page has no turned outline to draw.</li></ul>
<h3>Not verified</h3>
<ul><li>A phone: there is no Tab key. The "next" key of the on-screen keyboard and TalkBack's swipe order were not run. With a keyboard connected, press Tab and read the count in the status line under the picture.</li>
<li>Shadow trees, slots, frames, <code>focusgroup</code> and <code>reading-flow</code> are not followed by the rule.</li></ul>
<p><a href="https://html-in-canvas.page/focus-path/">Open Focus order drawn as a path</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>DOM drawn across a fold</title>
<link>https://html-in-canvas.page/fold/</link>
<guid isPermaLink="true">https://html-in-canvas.page/fold/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>devicePosture</category>
<category>viewport.segments</category>
<category>updateElementGeometry</category>
<description>Two panes placed by devicePosture and viewport.segments, and one element drawn across the hinge. A fold control stands in for the device: buttons and text fields work on a half drawn at 100°.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/fold/"><img src="https://html-in-canvas.page/fold/social.jpg" width="1200" height="630" alt="The page &quot;DOM drawn across a fold&quot;"></a></p>
<p><strong>Question:</strong> What can a canvas that draws live DOM do with the posture and the viewport segments of a foldable: place panes on each half, draw one element across the hinge, and keep input working on a tilted half?</p>
<p><strong>Short answer:</strong> All three work with a simulated fold. A real foldable hasn't been tried.</p>
<p>
A foldable device reports its posture with <code>navigator.devicePosture</code> and the rectangle of each screen half with
<code>viewport.segments</code>. I wanted to know what one canvas that draws DOM can do with those two values: place a pane on each half,
draw one element across the fold, and keep buttons and text fields working where they are drawn. A fold control stands in for the device,
so the page works on a flat screen. Change the angle, then press the buttons and type in the picture.
</p>
<h3>How it works</h3>
<p>
The canvas has two children, a content pane and a controls pane. When the posture is <code>folded</code>, each pane gets the rectangle of one
segment. When it is <code>continuous</code>, the content pane covers the whole screen and the controls pane becomes a bar. The panes are
resized with CSS, so the browser lays them out again, and the canvas draws them at their new place. A pane that changes place slides there over
320 ms, drawn at sizes between the two.
</p>
<p>
The fold control draws a picture of a folded device. Each half is cut into strips 8 px long that run beside the fold. A strip
further from the hinge is nearer the eye, so it's drawn wider. Each strip is one <code>drawElementImage()</code> call with a clip and a
scale. Next to the hinge the angle changes over 16 px, which is why the text curves there. On a real foldable none of this is drawn,
because the screen is bent already. There the canvas covers the window and only shades the crease.
</p>
<p>
"Open" and "Close" swing the angle to 180° and to 60° with a damped motion. In the simulated picture the half that holds the controls is drawn at one fixed tilt and only the other half turns, and the scale is chosen once for every angle, so the controls stay in the same place on the screen while the angle changes. On a real device the same picture is played when
<code>devicePosture</code> fires <code>change</code>: the API gives no angle, so on <code>"continuous"</code> the canvas draws the two halves
as slabs that start at 90° and swing flat over 1.1 seconds, with the live panes on them. A light band crosses each half and the shadow
under the device grows as the halves lift.
</p>
<p>
A hinge with a width hides pixels. A window that spans a dual-screen device has rows that no screen shows. With "Cut the picture" on, the
canvas lays the content out shorter by the width of the hinge and draws it in two pieces, one on each side, so no row is hidden.
With it off, the hinge covers part of the content, which is what a spanning window does without a canvas.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Layout by posture needs no canvas. Drawing one element across the fold does.</strong> CSS can place two elements with <code>env(viewport-segment-*)</code> and the <code>device-posture</code> media feature. CSS can't remove the rows of one element that fall under a hinge. A canvas can: it draws the element twice with a clip, before and after the hinge.</li>
<li><strong>A tilted half keeps exact hit testing.</strong> One half of a folded surface is a plane. <code>updateElementGeometry()</code> accepts a matrix with a perspective row, so a button on a half that is drawn at 100° is found by <code>elementFromPoint()</code> where it is drawn, and typing, the range slider and the checkboxes work there.</li>
<li><strong>An element across both halves has one hit box and two planes.</strong> The page gives the hit box to the half under the pointer, in <code>pointermove</code> and <code>pointerdown</code> listeners. With a mouse that is always in time. A touch has no <code>pointermove</code> before it: the <code>pointerdown</code> of a first tap on the other half is aimed with the old hit box, but the listener moves the box before the browser picks the target of the <code>click</code>, so the tap still follows a link after a 30 px hinge (emulated touch, Chromium 157). Controls that act on <code>pointerdown</code>, such as a range slider, would miss on that first touch. With no hinge the two planes differ only by the perspective, a few pixels near the fold.</li>
<li><strong>The curve next to the hinge is drawn but not hit tested.</strong> The matrix describes the flat part of each half. In the 16 px next to the hinge the picture is curved and the hit box is not, so a target there is off by up to 2 px at 90°.</li>
<li><strong>The posture and the segments were read through DevTools emulation only.</strong> In Chromium 157, <code>Emulation.setDeviceMetricsOverride</code> with a display feature gives two entries in <code>viewport.segments</code> and <code>devicePosture.type</code> <code>"folded"</code>, and "Use this device's fold" places the panes on them. <code>visualViewport.segments</code>, the older name, doesn't exist in this build.</li>
<li><strong>Not verified on a foldable.</strong> Segment rectangles on a real device, the hinge width a dual-screen device reports, how the on-screen keyboard changes the segments, and whether the crease shading lines up with the physical crease all need the hardware.</li>
<li><strong>The API has no fold angle, so the opening is played, not tracked.</strong> The posture is one of two words. A picture that follows the hinge as a hand opens it isn't possible with this API. The page starts a fixed 1.1 second swing when the word changes to <code>"continuous"</code>, and a shorter one when it changes to <code>"folded"</code>. With emulated posture changes the swing plays and the panes stay live during it. How it looks against the real movement of a hinge isn't known.</li>
<li><strong>The panes are live during the swing.</strong> Every frame redraws both panes from the DOM and sets their hit boxes, at 60° as well as at 180°. The countdown keeps running on a slab in motion.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/fold.md">findings/fold.md</a> in the repository.</p>
<p>From the hardware tier of the Chrome APIs plan. Each page has an on-page control that stands in for the device. Tested in headless Chromium 157 with a mouse, emulated touch and DevTools device emulation. No real foldable was used.</p>
<h3><code>/fold/</code>, <code>lib/fold-view.js</code></h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Place two canvas children from <code>devicePosture.type</code> and <code>viewport.segments</code></td><td>works</td><td>Each pane is resized with CSS to its segment and drawn there. A posture change relays the panes and the canvas draws the slide between the two places.</td></tr>
<tr><td>Draw a picture of a folded device on a flat screen with a 2D context</td><td>works</td><td>Each half is cut into 8 px strips beside the fold. A strip is one clipped <code>drawElementImage()</code> with its own scale. About 60 draws per frame for two panes.</td></tr>
<tr><td>Keep the controls still while the angle changes</td><td>works after a change</td><td>The first version drew both halves at half the fold angle and fitted the scale to each angle, so every control moved and changed size during a slider drag. Reported from a phone (2026-11-21). Now the half with the controls has one fixed tilt, only the other half turns, and one scale is chosen for all angles from 60° to 180°.</td></tr>
<tr><td>Hit testing on a half drawn at 90° to 100°</td><td>works</td><td>One half is a plane, so <code>updateElementGeometry()</code> gets a matrix with a perspective row. <code>elementFromPoint()</code> at the drawn centre of a button returns it, and the box centre is within 1.2 px. Taps, typing, a slider drag and checkboxes work there.</td></tr>
<tr><td>One element across both halves</td><td>works for one pointer</td><td>Two planes, one hit box. The box follows the pointer. A cold tap on the other half still clicks the right target, because a <code>pointerdown</code> listener moves the box before the click is aimed. The <code>pointerdown</code> itself goes to the old place.</td></tr>
<tr><td>Cut one element at a hinge and continue after it</td><td>works</td><td>The element is laid out shorter by the hinge width and drawn twice with a clip. CSS has no way to remove rows from the middle of an element.</td></tr>
<tr><td>Play the hinge opening when <code>devicePosture</code> changes</td><td>works, as a fixed swing</td><td>The API reports two words and no angle, so the opening cannot follow a hand. On <code>"continuous"</code> the canvas draws both halves as slabs that swing from 90° to flat in 1.1 s, with the panes live on them. Tested with emulated posture changes only.</td></tr>
<tr><td><code>viewport.segments</code> and <code>devicePosture</code> through <code>Emulation.setDeviceMetricsOverride</code></td><td>works</td><td>A display feature gives two segments and <code>"folded"</code>. <code>visualViewport.segments</code> does not exist in 157.</td></tr>
<tr><td>Playwright <code>page.screenshot()</code> during that emulation</td><td>resets it</td><td>Playwright sends its own metrics override, which drops the display feature. Use CDP <code>Page.captureScreenshot</code>.</td></tr></tbody></table>
<p>Not verified: any real foldable. Segment rectangles, the reported hinge width of a dual-screen device, the segments while the on-screen keyboard is open, and whether the shaded crease lines up with the physical one. The API reports no fold angle, so a real device cannot drive the angle of the picture.</p>
<p><a href="https://html-in-canvas.page/fold/">Open DOM drawn across a fold</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Form controls in a drawn setting</title>
<link>https://html-in-canvas.page/form-scenes/</link>
<guid isPermaLink="true">https://html-in-canvas.page/form-scenes/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawable descendants</category>
<category>drawElementImage</category>
<category>captureElementImage</category>
<category>form controls</category>
<category>disabled</category>
<description>A form drawn as an exploded diagram with its labels as call-outs, a date input on a wall calendar that tears off a sheet for each month, a file input as the slot of a letter box, and a fieldset that frosts over when it's disabled. Every label, input and button is the real element.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/form-scenes/"><img src="https://html-in-canvas.page/form-scenes/social.jpg" width="1200" height="630" alt="The page &quot;Form controls in a drawn setting&quot;"></a></p>
<p><strong>Question:</strong> When a canvas draws a form's labels, fields, file input and fieldset as parts of a picture (pulled apart, sheared, on a calendar, behind frost), do label activation, the native pickers, the file list and the disabled state still work at the drawn places?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. A label drawn away from its field still focuses it, a sheared field is hit inside its parallelogram, a tap on a drawn file input opens the file chooser, and a press on a disabled control reaches the canvas as pointerdown with no click. A picture taken with captureElementImage() keeps an input's old value, and drawing it moves the live input's hit region.</p>
<p>
Four ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>, built. Each canvas draws a scene and puts real form controls in it:
labels pulled away from their fields, a date input on a wall calendar, a file input as the slot of a letter box, and a fieldset
under frost. Tap a call-out, tap a day, post some files, and lock the panel. The text under each canvas is read from the form.
</p>
<h3>How it works</h3>
<p>Each canvas holds its controls as descendants marked <code>drawable</code>. A <code>paint</code> handler draws the scene with 2D calls and each control with <code>drawElementImage()</code>, which also moves the control's hit region to where it was drawn. The page uses 2D canvases only. A demo starts when its section comes near the screen.</p>
<ul>
<li><b>One design space.</b> Every scene is laid out 380 units wide and scaled to the canvas, so a control is drawn smaller on a narrow phone and its hit region is scaled with it.</li>
<li><b>The control is the state.</b> No scene keeps a copy of a value. The paint handler reads <code>value</code>, <code>files</code>, <code>validity</code> and <code>disabled</code>.</li>
<li><b>A picture of an earlier state.</b> <code>captureElementImage()</code> returns a picture that stays as it was when the element changes. The calendar keeps two and calls <code>close()</code> on each when its sheet has fallen.</li>
<li><b>Plain HTML when the canvas can't draw.</b> Without the API, or after a lost context, the controls are moved out of the canvas and shown as an ordinary form.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch at 412 px wide. Nothing on this page has been run on a phone.</p>
<ul>
<li><b>A label works when it's drawn away from its field.</b> The label and the field are separate <code>drawable</code> elements joined by <code>for</code>. A tap on the drawn label focused the text field, and a tap on the label of the checkbox toggled it. No code on the page moves focus.</li>
<li><b>A sheared field is hit inside its parallelogram.</b> <code>getBoundingClientRect()</code> returns the bounding box of the sheared shape (150 by 81 px for a 150 by 36 px field at a shear of -0.3). <code>elementFromPoint()</code> in the empty corner of that box returns the canvas. A tap near the raised end of the field focused it, and typing went into it.</li>
<li><b>The browser's validation message appears at the sheared field.</b> After Send with the name empty, the message pointed at the field where the canvas had drawn it (seen in a screenshot).</li>
<li><b>A picture from <code>captureElementImage()</code> keeps the old value.</b> A picture of a date input, taken before its value changed, matched the old pixels in every place after the change. The calendar draws those pictures on the sheet that falls.</li>
<li><b>Drawing a picture of an element moves the element's hit region.</b> After the picture of an input was drawn 80 px lower, <code>getBoundingClientRect()</code> of the live input reported the lower place. A draw of the input with <code>globalAlpha</code> 0 at its own place put the region back. The calendar does this on every frame of the fall.</li>
<li><b>A value written by script raises <code>paint</code> and no <code>input</code> event.</b> That holds for a date value, a month value and <code>stepUp()</code> on a month input.</li>
<li><b>A tap on a drawn file input opens the file chooser.</b> The chooser reported <code>multiple</code>. Files chosen there, and a file dropped on the drawn input, arrived in <code>input.files</code> with a <code>change</code> event.</li>
<li><b>The file input's own text is in its picture.</b> Writing <code>input.files</code> from a <code>DataTransfer</code> changed the pixels of the input (its count of files) and raised <code>paint</code>. That write raises no <code>change</code> event, so the page updates its scene itself.</li>
<li><b>An element made for each file is tapped where it lies.</b> Each print and envelope is a <code>&lt;button drawable&gt;</code> appended to the canvas and drawn turned. A tap on one took its file out of <code>input.files</code>.</li>
<li><b>One <code>disabled</code> attribute on a drawn fieldset does what it does outside a canvas.</b> Every control except the checkbox in the legend matched <code>:disabled</code>, was left out of <code>FormData</code> and wasn't validated. The picture changed to the disabled colours and <code>paint</code> was raised.</li>
<li><b>A disabled control is still found, and a press on it still reaches the canvas.</b> <code>elementFromPoint()</code> returns the disabled button. A tap on it raised <code>pointerdown</code> with the button as target, and no <code>click</code> on the button. The frost uses that press to melt a patch.</li>
<li><b><code>ctx.filter</code> applies to <code>drawElementImage()</code>.</b> With <code>blur(4px)</code>, a pixel beside a black and white edge read 93 where the plain draw read 0. Drawing the same element twice at the same place leaves its hit region where it was.</li>
<li><b>Not verified:</b> everything on a phone. In particular the Android date and month dialogs opened from the calendar, the Android file chooser and camera from the letter box, large photos, the on-screen keyboard over a sheared field, and the speed of the blur. A screen reader hasn't been tried on any of the four.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/form-scenes.md">findings/form-scenes.md</a> in the repository.</p>
<p>Four ideas from the element catalogue (group 13 of the backlog in PLAN.md): the exploded form diagram, the wall calendar round a date input, the file input on a letter box and the disabled panel. Measured in headless Chromium 157 (C157) on 2026-11-21 with a mouse, a keyboard and emulated touch at 412 px wide. The page's ten live checks pass there. <code>node tools/form-scenes/check.mjs</code> drives the four demos with taps, typing, a file chooser and a file drop (29 steps, all pass). <code>npm run check:jank -- /form-scenes/</code> passes (0 WebGL contexts, 4.6 MB of canvas, 0 readbacks). Nothing here has been run on Chrome 159 on Android (A159).</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Exploded form: every <code>&lt;label for&gt;</code> and every field is its own <code>drawable</code> element. Labels are drawn as call-outs away from their fields (167 px in the live check)</td><td>works</td><td>A tap on a drawn label focused its text field (<code>document.activeElement</code>), and a tap on the checkbox's label toggled it. <code>label.control</code> is unchanged. No page code moves focus.</td></tr>
<tr><td>A text field drawn under a shear (<code>ctx.transform(1, -0.22, 0, 1, 0, 0)</code>)</td><td>works</td><td>A tap near the raised end focused the field and typed text went into it. <code>getBoundingClientRect()</code> is the bounding box of the sheared shape: 150 by 81 px for a 150 by 36 px field at a shear of -0.3 (live check).</td></tr>
<tr><td>Hit testing in the empty corner of a sheared field's bounding box</td><td>returns the canvas</td><td>The hit region is the parallelogram, not its bounding box (live check).</td></tr>
<tr><td>Browser validation message for a sheared field</td><td>shown at the field</td><td>After Send with the name empty the message pointed at the field where it was drawn (screenshot, C157 headless). The browser then focuses that field.</td></tr>
<tr><td>Wall calendar: <code>&lt;input type="date"&gt;</code> and <code>&lt;input type="month"&gt;</code> drawn on a sheet. The grid, month name and pen ring are canvas drawing from their values</td><td>works</td><td>A tap on the grid writes <code>date.value</code> and dispatches <code>input</code>. The buttons call <code>month.stepUp()</code> and <code>stepDown()</code>.</td></tr>
<tr><td>A value written by script (<code>date.value</code>, <code>month.value</code>, <code>month.stepUp()</code>)</td><td><code>paint</code>, no <code>input</code> event</td><td>One <code>paint</code> each (live check). The page calls its own handler after <code>stepUp()</code>.</td></tr>
<tr><td>Keeping the picture of an input's old value with <code>captureElementImage()</code></td><td>works</td><td>The picture taken before the value changed matched the old pixels in 5,760 of 5,760 places after the change, across frames (live check). The sheet that is torn off is drawn with those pictures, so it shows the old date while the live inputs below show the new one. The page keeps 2 pictures open at rest and at most 4, and closes each when its sheet has fallen.</td></tr>
<tr><td>Drawing a picture of an element</td><td>moves the live element's hit region</td><td>After <code>drawElementImage(picture, 10, 90, …)</code> the input's <code>getBoundingClientRect()</code> reported y 90 in place of y 10 (live check). The calendar draws the falling sheet last, so it follows it with a draw of each input at <code>globalAlpha</code> 0 at its real place. During the fall the date input stayed 0 px from its place.</td></tr>
<tr><td>Letter box: <code>&lt;input type="file" multiple&gt;</code> drawn as the slot, styled with <code>::file-selector-button</code></td><td>works</td><td>A tap on the drawn input opened the file chooser (Playwright <code>filechooser</code> event, <code>isMultiple()</code> true). Files set there arrived in <code>input.files</code> with a <code>change</code> event.</td></tr>
<tr><td>Dropping a file on the drawn file input</td><td>works</td><td>CDP <code>Input.dispatchDragEvent</code> (<code>dragEnter</code>, <code>dragOver</code>, <code>drop</code>) at the drawn place replaced <code>input.files</code> with the dropped file and raised <code>change</code>.</td></tr>
<tr><td>Writing <code>input.files</code> from a <code>DataTransfer</code></td><td>picture changes, <code>paint</code>, no <code>change</code></td><td>The input's own text (its count of files) is part of its picture: 572 pixels changed and one <code>paint</code> was raised (live check).</td></tr>
<tr><td>One <code>&lt;button drawable&gt;</code> per file, appended to the canvas later, drawn turned on the mat</td><td>works</td><td>A tap on a print took its file out of <code>input.files</code>. An element that is waiting to be drawn is parked with <code>updateElementGeometry()</code>.</td></tr>
<tr><td>Small copies of chosen pictures</td><td>works in C157</td><td><code>createImageBitmap(file, { resizeWidth: 176 })</code>, then <code>OffscreenCanvas.convertToBlob()</code>, on the <code>change</code> event. An SVG file fails <code>createImageBitmap()</code> and is used as it is if it is under 1 MB.</td></tr>
<tr><td>Disabled panel: <code>disabled</code> set on a <code>&lt;fieldset drawable&gt;</code> by a checkbox in its legend</td><td>works</td><td>6 of 7 controls match <code>:disabled</code>. The checkbox in the legend does not and still takes a tap. <code>FormData</code> is empty and the required field is not validated (<code>willValidate</code> false).</td></tr>
<tr><td><code>paint</code> after <code>fieldset.disabled = true</code></td><td>raised when the picture changes</td><td>One <code>paint</code>, 678 pixels changed, for a fieldset with a text field and a checkbox (live check). A fieldset holding only a button with the site's button style raised none, because that style has no disabled look and no pixel changed.</td></tr>
<tr><td>A press on a disabled control in a canvas</td><td><code>pointerdown</code> reaches the canvas, no <code>click</code> on the control</td><td><code>elementFromPoint()</code> returns the disabled button. A tap on it raised <code>pointerdown</code> on the canvas with the button as target and 0 <code>click</code> events on controls. A tap on the disabled text field did not focus it.</td></tr>
<tr><td>Frost: the fieldset drawn a second time with <code>ctx.filter = 'blur(…)'</code>, clipped</td><td>works</td><td><code>ctx.filter</code> applies to <code>drawElementImage()</code>: beside a black and white edge the plain draw read 0 and the blurred draw 93 (live check). Several draws of one element at one place leave its hit region there.</td></tr>
<tr><td>No API, and a lost context</td><td>plain HTML</td><td>With <code>--disable-blink-features=CanvasDrawElement</code> all four canvases are replaced by their controls and each form still reports its values. A dispatched <code>contextlost</code> on one canvas replaced that canvas after 1.5 s.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The site's stylesheet gives <code>&lt;button&gt;</code> no disabled look. A check that disabled a fieldset holding only a button saw no <code>paint</code> and no changed pixel. The page adds <code>button:disabled { opacity: 0.45 }</code> for the panel, and the check uses a text field and a checkbox.</li>
<li>After a failed submit the browser focuses the first invalid field, and the <code>focusin</code> handler replaced the line about the failure. The handler now leaves the line alone for 200 ms after an <code>invalid</code> event.</li>
<li>The falling sheet has to be drawn after the sheet below it, and its pictures then take the inputs' hit regions with them. The fix is the draw at <code>globalAlpha</code> 0, not a change of draw order.</li>
<li>A <code>&lt;canvas&gt;</code> rule with <code>display: block</code> beats the <code>hidden</code> attribute (found on <code>/instruments/</code>). This page writes <code>canvas.scene[hidden] { display: none }</code>.</li>
<li><code>lib/stage-2d.js</code> has a <code>fixtureCanvas()</code> helper that makes a drawable canvas with <code>willReadFrequently: true</code>. This page does not use it. Its checks read from a <code>drawImage()</code> copy.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the four demos by touch. <code>node tools/form-scenes/check.mjs</code> covers touch through Playwright's emulated touchscreen only.</li>
<li>Whether the canvases are kept on the phone. The page has four 2D canvases (4.6 MB), no WebGL, no readback from a drawable canvas and no <code>willReadFrequently</code>. Open the page and scroll to the end. A lost canvas is replaced by plain controls with a note.</li>
<li>The Android date and month dialogs: whether a tap on the drawn date input opens the dialog, and whether the sheet turns when a date in another month is chosen. Open <code>/form-scenes/#calendar</code> and tap the date field.</li>
<li>The Android file chooser, the camera option and a 12 megapixel photo through <code>createImageBitmap()</code> with <code>resizeWidth</code>. Open <code>/form-scenes/#letterbox</code>, tap the slot and choose several photos.</li>
<li>A file dragged from a file manager with a real pointer. The drop was sent through CDP.</li>
<li>The on-screen keyboard over a sheared field, and whether the canvas stays in view. Tap a call-out.</li>
<li>The speed of <code>ctx.filter</code> blur on a phone GPU while the frost grows (about 1 s of frames).</li>
<li>Where Android shows the validation message for a sheared field. Press Send with the name empty.</li>
<li>A screen reader on any of the four. The grid of days is <code>aria-hidden</code> and the date input is the control it should use.</li></ul>
<p><a href="https://html-in-canvas.page/form-scenes/">Open Form controls in a drawn setting</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Form effects driven by the paint event</title>
<link>https://html-in-canvas.page/form-state/</link>
<guid isPermaLink="true">https://html-in-canvas.page/form-state/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>paint event</category>
<category>drawElementImage</category>
<category>form controls</category>
<category>ctx.filter</category>
<description>Ink that arrives wet with each typed letter, a keypad that sinks round the pressed key, a colour input that lights its scene, a &lt;progress&gt; drawn as a tank of liquid and a search field that blurs the links that don't match. Each effect reads the control's state in the paint handler. Four of them have no listener on the control.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/form-state/"><img src="https://html-in-canvas.page/form-state/social.jpg" width="1200" height="630" alt="The page &quot;Form effects driven by the paint event&quot;"></a></p>
<p><strong>Question:</strong> Can an effect on a form control be driven by the paint event alone, reading value, :active, :focus and position in the handler, with no input, pointer or focus listener?</p>
<p><strong>Short answer:</strong> Yes for four of the five, as long as the state changes a pixel of the control's picture. A touch press didn't set :active on a button drawn in a canvas (Chromium 157, emulated touch), so the pressed button has a pointerdown listener as a second route.</p>
<p>
Five form ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>. In each one the effect has no listener on the control. A key press, a
pressed button, a new colour, a new progress value or a focus ring changes the control's picture, the browser raises <code>paint</code> on
the canvas, and the paint handler reads the control's state (<code>value</code>, <code>:active</code>, <code>position</code>,
<code>:focus</code>) and draws the effect from it. I wanted to know how far that goes before a listener is needed. It went all the way
for four of the five. The pressed button needed a listener for touch.
</p>
<h3>How it works</h3>
<p>The browser raises <code>paint</code> on a drawable canvas when the picture of one of its <code>drawable</code> descendants changes. Typing changes a textarea's picture, <code>:active</code> and <code>:focus</code> styles change a button's or a field's, and a new <code>value</code> changes a colour swatch or a progress bar. So the paint handler is called at the moments an effect needs, and it can read the state from the control:</p>
<ul>
<li><b>The handler compares.</b> <code>paint</code> says that something changed, and <code>event.changedElements</code> says which element, but not what. The ink demo keeps the last length of the value, the dent demo keeps whether a button was active, and the others ease towards the current state.</li>
<li><b>The state must be in the picture.</b> A state that changes no pixel raises no <code>paint</code>. The pressed style of the keys, the focus border of the fields and the faint browser bar inside the tank are there for that reason.</li>
<li><b>Animation is asked for from inside the handler.</b> While an effect is still moving, the handler asks for one more <code>paint</code> with <code>requestPaint()</code> in the next frame. When it has settled the page draws nothing until the control changes again.</li>
<li><b>Extra draws move the hit region.</b> The ink and the dent draw their element several times with different transforms, and input goes to the place of the last draw. Each ends with a draw that is clipped away completely at the flat position.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch. Not yet run on a phone.</p>
<ul>
<li><b>Four of the five effects need no listener.</b> Typing, a value written by script, a new colour, a new progress value, focus and blur each raised <code>paint</code>, and the handler read the state from the control. After each effect settled the page drew nothing: 0 paint events in 0.8 s for the lamp and the tank, and 2 in 0.7 s for the textarea, whose caret blinks.</li>
<li><b>A touch press didn't set <code>:active</code> on a button drawn in a canvas.</b> With a mouse and with Space on a focused key the button matched <code>:active</code> and the dent ran from <code>paint</code> alone. With an emulated touch press held for 0.45 s no button matched <code>:active</code>, though the tap still clicked the key. A button outside the canvas matched <code>:active</code> for about 20 ms after the same touch. The dent has a <code>pointerdown</code> listener as a second route, and the line under the demo counts which route saw each press.</li>
<li><b>A state that changes no pixel raises no <code>paint</code>.</b> A hidden input's value and an attribute with no style changed with no paint event. The pressed style, the focus border and the faint browser bar in the tank are what make the state visible to the canvas.</li>
<li><b><code>event.changedElements</code> names the control.</b> It held the textarea after its value changed and the colour input after its value changed. It says which element changed, not what changed, so the handler keeps the last value to compare.</li>
<li><b><code>ctx.filter</code> applies to <code>drawElementImage()</code>.</b> A box drawn through <code>blur(6px)</code> had alpha 42 at 5 px outside its edge. The wet ink and the links set aside by the search are the element drawn again through a blur.</li>
<li><b><code>createValueRange()</code> gives the box of a typed character at the drawn place.</b> The ink is put at the middle of that box. The textarea is drawn several times with different scales, so the box is read before the extra draws of the next frame move it.</li>
<li><b>A draw inside an empty clip moves the hit region and adds no pixels.</b> The ink and the dent end each frame with one at the flat position. After the ink, a tap near the start of the first line put the caret at index 1.</li>
<li><b>A triangle mesh bends a panel of buttons in a 2D context.</b> 144 clipped draws of the same element, each with the affine transform of its triangle. A clip 0.6 px larger than each triangle hides most of the lines between neighbours. Faint diagonal lines can still be seen on the dark panel.</li>
<li><b><code>source-atop</code> after one draw of an element keeps later fills inside its picture.</b> The liquid has the rounded outline of the <code>&lt;progress&gt;</code> element with no clip path: alpha 0 in the rounded corner.</li>
<li><b>Removing <code>value</code> from a <code>&lt;progress&gt;</code> raises <code>paint</code></b> with <code>appearance: none</code> too (1 event), and <code>position</code> is then -1. The browser's own indeterminate look raised 4 paint events in 0.5 s.</li>
<li><b>A link drawn blurred and dimmed is still found at its drawn place</b> by <code>elementFromPoint()</code>.</li>
<li><b>Not verified:</b> everything on a phone. In particular whether a touch press sets <code>:active</code> on Chrome 159 on Android (the line under the keypad says), the on-screen keyboard over the ink and the search field, the Android colour dialog opened from the drawn lamp, and the speed of 144 draws per frame.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/form-state.md">findings/form-state.md</a> in the repository.</p>
<p>Five ideas from the element catalogue (group 12 of the backlog in PLAN.md). Measured in headless Chromium 157 (C157) on 2026-11-21 with a mouse, a keyboard and emulated touch at 412 px wide. The page's eight live checks pass there, and <code>node tools/form-state/check.mjs</code> drives the five demos with real input (30 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: can an effect on a form control be driven by the <code>paint</code> event alone, with the handler reading the control's state, and no input, pointer or focus listener on the control?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Ink per keystroke: a <code>&lt;textarea drawable&gt;</code> with no listener. The paint handler compares <code>value.length</code> with the last length it saw</td><td>works</td><td>Each typed character raised <code>paint</code>. Three typed letters were counted as three. Backspace is not counted because the length fell.</td></tr>
<tr><td>Where the typed letter is</td><td><code>createValueRange(i, i + 1).getBoundingClientRect()</code></td><td>The box is at the drawn place of the textarea (live check: 19.8 px and 74.0 px into the field for the 2nd and 7th characters of a monospace line).</td></tr>
<tr><td>Wet ink: the textarea drawn a second time in a clipped circle with <code>ctx.filter = 'blur()'</code> and a larger scale</td><td>works</td><td><code>ctx.filter</code> applies to <code>drawElementImage()</code> (live check: alpha 42 at 5 px outside the edge of a box drawn through <code>blur(6px)</code>).</td></tr>
<tr><td>Putting input back after the extra draws</td><td>a draw inside an empty clip</td><td>It adds no pixels and moves the hit region (live check). After the ink, a tap near the start of the first line put the caret at index 1.</td></tr>
<tr><td>Idle cost of the ink</td><td>2 paint events in 0.7 s</td><td>The caret blink repaints the textarea. The handler draws one flat picture for each.</td></tr>
<tr><td>Dent: the paint handler reads <code>panel.querySelector('button:active')</code>. Mouse</td><td>works</td><td>The <code>:active</code> style changes the picture, <code>paint</code> is raised, and the handler finds the button.</td></tr>
<tr><td>The same with Space held on a focused key</td><td>works</td><td>The button matches <code>:active</code> while the key is down.</td></tr>
<tr><td>The same with a touch press (CDP touch events, held 0.45 s)</td><td>fails: no button matches <code>:active</code></td><td>Polled every 16 ms during and after the press. The tap still raised <code>pointerdown</code>, <code>pointerup</code> and <code>click</code> on the button. A button outside the canvas matched <code>:active</code> for about 20 ms after the same touch. Whether Chrome 159 on Android behaves the same is not verified.</td></tr>
<tr><td>Second route for touch</td><td><code>pointerdown</code> listener</td><td>The listener remembers the key and calls <code>requestPaint()</code>. The handler uses it only when no button matches <code>:active</code>. The line under the demo counts the two routes separately, so the page reports the answer on the device that opens it.</td></tr>
<tr><td>Bending a panel of buttons in a 2D context</td><td>triangle mesh</td><td>An 8 by 9 grid of moved corners, 144 triangles, each a clipped <code>drawElementImage()</code> of the whole panel with the affine transform of its triangle. A clip 0.6 px larger than the triangle hides most seams. Faint diagonal lines remain on the dark panel. The first version scaled 99 square tiles, and its seams were plain to see.</td></tr>
<tr><td>Colour input as a lamp: the handler reads <code>input.value</code>; buttons only write <code>value</code></td><td>works</td><td>Writing <code>value</code> raised 1 paint event and <code>changedElements</code> held the input (live check, swatch pixel 200,0,0 then 0,200,0). Wall pixel 194,71,97 under #ff3b6b and 96,182,128 under #62f0a0. 0 paint events in 0.8 s once the colour settled.</td></tr>
<tr><td>Light on a scene</td><td><code>multiply</code> then <code>screen</code></td><td>The card is drawn in its own colours, the whole canvas is multiplied by a gradient of the colour, and a glow is added. The input is drawn last so it shows the chosen colour.</td></tr>
<tr><td>Liquid: the handler reads <code>progress.position</code></td><td>works</td><td>Writing <code>value</code> raised 1 paint event. Removing <code>value</code> raised 1 with <code>appearance: none</code> and 4 in 0.5 s with the browser's look, and <code>position</code> is -1 (live checks).</td></tr>
<tr><td>The tank's outline</td><td><code>source-atop</code></td><td>The element is drawn first on an empty canvas. Fills made with <code>source-atop</code> stay inside its pixels: alpha 0 in the rounded corner (live check).</td></tr>
<tr><td>Search field: the handler reads <code>field.matches(':focus')</code> and <code>value</code></td><td>works</td><td>Focus changes the border, which raises <code>paint</code>. Typing "se" left 2 of 6 links sharp. Blur was seen after <code>blur()</code>.</td></tr>
<tr><td>A link drawn through a blur filter with lower alpha</td><td>still a link</td><td><code>elementFromPoint()</code> at its drawn place returned the link.</td></tr>
<tr><td>A state that changes no pixel</td><td>no <code>paint</code></td><td>A hidden input's value and an unstyled attribute changed with 0 paint events (live check). Each demo keeps its state in the picture: a pressed style, a focus border, a faint <code>::-webkit-progress-value</code>.</td></tr>
<tr><td>A lost context</td><td>plain controls</td><td>One <code>contextlost</code> event on one canvas stops all five and shows the controls as plain HTML (5 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Scaling square tiles about their own centres leaves gaps and overlaps wherever neighbours have different scales. Moving the shared corners and mapping triangles has no gaps.</li>
<li><code>:active</code> under touch could not be seen by reading it once during the press: it had to be polled, inside and outside a canvas, to tell "never set" from "set for one frame".</li>
<li>The shading of the dent is drawn with <code>source-atop</code> after the mesh, so it stays inside the panel's rounded outline with no clip path.</li>
<li>The <code>&lt;output&gt;</code> under a demo is rewritten by the paint handler. It has a fixed minimum height so the page below does not move.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: all five by touch. Open <code>/form-state/</code> and try each.</li>
<li>Whether a touch press sets <code>:active</code> on a drawn button on the phone. Press a key on the keypad and read the line under it: it counts presses seen through <code>:active</code> and presses only the listener saw.</li>
<li>The on-screen keyboard over the ink and the search field, and whether the canvas stays in view.</li>
<li>The Android colour dialog opened by a tap on the drawn lamp.</li>
<li>The speed of 144 clipped draws per frame (the dent) and of blurred draws (ink, search) on a phone GPU.</li>
<li>A screen reader on any of the five.</li></ul>
<p><a href="https://html-in-canvas.page/form-state/">Open Form effects driven by the paint event</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Friction log: where the API did not do what I expected</title>
<link>https://html-in-canvas.page/friction/</link>
<guid isPermaLink="true">https://html-in-canvas.page/friction/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>updateElementGeometry</category>
<category>hit testing</category>
<category>paint</category>
<category>bugs</category>
<description>Every place found so far where HTML-in-canvas, or a Chrome API used with it, didn't do what the person writing a page expected. Each entry has what was expected, what happened, the browser, where to see it, the workaround and a status: browser bug, API gap, the API as built, or my mistake. Nineteen entries are re-run in the visitor's browser.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/friction/"><img src="https://html-in-canvas.page/friction/social.jpg" width="1200" height="630" alt="The page &quot;Friction log: where the API did not do what I expected&quot;"></a></p>
<p><strong>Question:</strong> Where did HTML-in-canvas not do what a developer expected, and for each case is it a browser bug, a gap in the API, the API working as built, or a mistake in the page?</p>
<p><strong>Short answer:</strong> 79 entries on 2026-11-21: 18 that look like browser bugs, 17 API gaps, 21 where the API works as built, 8 mistakes of mine, 7 from libraries or the test browser, 8 with no known cause. All 19 probes reproduce in Chromium 157.</p>
<p>
Every place found so far where HTML-in-canvas, or a Chrome API used with it, did not do what the person writing a page expected.
Each entry says what was expected, what happened, in which browser, where to see it, what the pages do now, and whether it is a
browser bug, a gap in the API, the API working as built, or my mistake. Nineteen entries have a probe: the live checks at the end
of the page re-run them in this browser and mark each entry "still happens" or "does not happen".
</p>
<h3>How it works</h3>
<ul>
<li>The entries are written by hand in <code>/friction/entries.js</code> from <code>FINDINGS.md</code>, the "Things that bit", "Chromium bugs" and "API requests" sections of the files in <code>findings/</code>, and <code>docs/graphics-rules.md</code>. Each names the file that holds the full record.</li>
<li>"Measured" means a live check or a script produced it in headless Chromium 157.0.8103.78 with software rendering (C157) unless the entry names another browser. "Reported" means I saw it on my phone, Chrome 159 on Android (A159), and wasn't reproduced in the test browser.</li>
<li>An entry with a probe is re-run here. The probe builds its own fixture on the test stage, away from the page, and never touches a visible canvas. No probe opens a WebGL context or a WebGPU device, and none reads a drawable canvas directly.</li>
<li>The probes wait for a press. Several of them ask <code>elementFromPoint()</code> on the test stage or count paint events over a third of a second, and a page should start with nothing else running.</li>
<li>A crash or a lost canvas is recorded on <a href="https://html-in-canvas.page/crashes/">/crashes/</a>. An entry here that has one links to it.</li>
</ul>
<h3>Findings</h3>
<p>State on 2026-11-21. Headless Chromium 157.0.8103.78 for "measured", Chrome 159 on Android for "reported".</p>
<ul>
<li><strong>79 entries.</strong> 18 look like browser bugs, 17 are things the API has no call for, 21 are the API working as built, 8 are my mistakes, 7 come from libraries or the test browser, and 8 have no known cause. The crashes and lost canvases on <code>/crashes/</code> are counted there.</li>
<li><strong>Hit testing has the most entries, 13.</strong> The last draw decides an element's one hit region, a draw with no pixels moves it, a source-rectangle draw shrinks it, and the browser remembers its answer for a point after the region moves. Most pages that draw an element twice or in pieces met at least one of these.</li>
<li><strong>Most of the time lost was to silence.</strong> A draw with no size, an SVG drawn with <code>offsetWidth</code>, a filter id that isn't found, cross-origin content and a nested drawable outside the window all draw wrongly or draw nothing and throw nothing. "No cached paint record for element" is the one error message for four different causes.</li>
<li><strong>All nineteen probes reproduce in Chromium 157</strong> at device scale factor 2 on 2026-11-21. At scale factor 1 the probe for a draw with no size can't decide.</li>
<li><strong>Nothing here has been filed.</strong> Each entry copies as plain text for a report.</li>
<li><strong>Not verified:</strong> every probe on Chrome 159 for Android. Press "Run the checks" on the phone. The entries about touch (<code>:active</code>, <code>touch-action</code> in a picker, a rotated range input) were measured with emulated touch only.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/friction.md">findings/friction.md</a> in the repository.</p>
<p>Measured in C157 (headless Chromium 157.0.8103.78 shell, software rendering) on 2026-11-21, at 412 px wide with emulated touch and device scale factor 2, and with <code>--force-device-scale-factor=2</code> and no viewport emulation. Nothing here has been run on A159.</p>
<p>The page collects every place recorded so far where HTML-in-canvas, or a Chrome API used with it, did not do what the person writing a page expected. The entries were gathered from <code>FINDINGS.md</code> ("Chromium bugs worth filing", "API changes that would help", the index), from the "Things that bit", "Chromium bugs" and "API requests" sections of the files in this folder, and from <code>docs/graphics-rules.md</code> and <code>docs/lost-contexts.md</code>. Crashes and lost canvases stay on <code>/crashes/</code>: the page lists them from <code>public/crashes/cases.js</code> and does not copy them.</p>
<h3>What the log holds</h3>
<table><thead><tr><th>Kind</th><th>Entries</th><th>What it means</th></tr></thead><tbody><tr><td>Browser behaviour that looks wrong</td><td>18</td><td>Candidates for a Chromium bug report. None is filed.</td></tr>
<tr><td>The API has no way to do it</td><td>17</td><td>Requests for the explainer.</td></tr>
<tr><td>The API as built, where it was not what I expected</td><td>21</td><td>Developer friction: no error, no warning or no line in the explainer said so.</td></tr>
<tr><td>My mistakes</td><td>8</td><td>Developer friction: the code or the test was wrong.</td></tr>
<tr><td>Libraries, bindings and the test browser</td><td>7</td><td>Friction from outside the API.</td></tr>
<tr><td>Seen, cause not found</td><td>8</td><td>Each needs a smaller page or a run on the device that showed it.</td></tr></tbody></table>
<p>79 entries. By area: hit testing 13, drawing 10, pictures 9, WebGL and WebGPU 9, lost canvases 8, form controls 6, paint event 6, layout 5, related APIs 4, tools 4, ElementImage 2, view transitions 2, accessibility 1.</p>
<h3>Probes</h3>
<p>Nineteen entries can be decided by script. <code>probes.js</code> has one function for each. The live checks run them on fixtures on the test stage and mark the entry "still happens" or "does not happen" in the browser that opened the page. A check fails while the behaviour is still there (<code>expect: 'fail'</code>).</p>
<table><thead><tr><th>Probe</th><th>Result in C157, 2026-11-21</th><th>Numbers</th></tr></thead><tbody><tr><td><code>drawElementImage()</code> with no size under <code>ctx.scale(devicePixelRatio)</code></td><td>measured: still happens</td><td>A 100 px box covers 200 CSS px at ratio 2. At ratio 1 the probe cannot decide.</td></tr>
<tr><td>The remembered hit-test answer after a move</td><td>measured: still happens</td><td>The asked point stays stale. A point 2 px away is right. An attribute toggle clears it.</td></tr>
<tr><td>Hit region after a source-rectangle draw and <code>updateElementGeometry()</code></td><td>measured: still happens</td><td>3 of 36 points after a 12 px piece of a 120 px element, 36 after a whole draw in an empty clip.</td></tr>
<tr><td>A draw at <code>globalAlpha</code> 0 moves the hit region</td><td>measured: still happens</td><td></td></tr>
<tr><td><code>getBoundingClientRect()</code> follows the last draw</td><td>measured: still happens</td><td>50 by 20 for a 100 by 40 px element drawn at half size.</td></tr>
<tr><td>Direct drawable children are laid out at the canvas origin</td><td>measured: still happens</td><td><code>offsetTop</code> 0 and 0, widths 29 and 47 px in a 300 px canvas.</td></tr>
<tr><td>A canvas child without <code>drawable</code></td><td>measured: throws</td><td>"Descendants passed to DrawElementImage must have the 'drawable' attribute".</td></tr>
<tr><td>A draw in the task that inserted the element</td><td>measured: throws</td><td>"No cached paint record for element". It draws after the next paint event.</td></tr>
<tr><td><code>&lt;slot drawable&gt;</code></td><td>measured: throws</td><td>"No cached paint record for element". The slotted child without its own attribute throws the <code>drawable</code> error.</td></tr>
<tr><td>An SVG drawn with <code>offsetWidth</code> and <code>offsetHeight</code></td><td>measured: draws nothing, throws nothing</td><td><code>offsetWidth</code> is <code>undefined</code>.</td></tr>
<tr><td><code>ctx.filter = 'url(#missing)'</code></td><td>measured: draws unfiltered, throws nothing</td><td></td></tr>
<tr><td>A canvas inside a drawable box with 20 px of padding</td><td>measured: still happens</td><td>Drawn 60 by 20 px in place of 80 by 40. Right with <code>contain: paint</code>.</td></tr>
<tr><td>A spread shadow and an outline outside the border box</td><td>measured: not in the picture</td><td></td></tr>
<tr><td>A change of a custom property that no rule uses</td><td>measured: no paint event</td><td>0 events in 300 ms. A background change gives 1.</td></tr>
<tr><td>An <code>ElementImage</code> in a second canvas</td><td>measured: refused</td><td><code>drawElementImage()</code> throws, <code>drawImage()</code> throws, <code>createImageBitmap()</code> rejects. No <code>[Symbol.dispose]</code>. A closed one throws "The ElementImage has been closed".</td></tr>
<tr><td>three.js method names</td><td>measured: missing</td><td><code>texElementImage2D</code> and <code>copyElementImageToTexture</code> are missing. <code>texElementSubImage2D</code> and <code>drawElementImageToTexture</code> are present.</td></tr>
<tr><td><code>navigator.devicePosture</code></td><td>measured: <code>type</code> and <code>onchange</code> only</td><td></td></tr>
<tr><td><code>getBoxQuads()</code></td><td>measured: missing on Element and Range</td><td></td></tr>
<tr><td><code>HTMLSelectElement.prototype.hidePicker</code></td><td>measured: missing</td><td><code>showPicker</code> is present.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The alpha convention of an element texture is recorded two ways in this folder. <code>webgpu.md</code> says premultiplied, from a texture readback. <code>gpu-video.md</code> says translucent controls were solid white until the shader multiplied colour by alpha. The log lists this as one entry and does not settle it.</li>
<li>Under Playwright's device emulation with <code>deviceScaleFactor: 2</code> the probe for a draw with no size reported the same doubling as with <code>--force-device-scale-factor=2</code>. The earlier note that emulation hides it was made with a different setup and was not re-tested here.</li>
<li>Text put into the entry cards after a probe would change their height and move the page. Each card has one fixed line for the result and the detail stays in the live check table.</li></ul>
<h3>Not verified</h3>
<ul><li>Every probe on A159. Open <code>/friction/</code> on the phone and press "Run these 19 checks". A check that passes there marks an entry that Chrome 159 no longer shows.</li>
<li>The entries about touch (<code>:active</code> under a touch press, <code>touch-action</code> in a picker, a rotated range input) come from emulated touch.</li>
<li>Whether any entry is already known to the Chromium or WICG trackers. None was searched for and none is filed.</li>
<li>The 60 entries without a probe were copied from the records named in each entry and were not re-run for this page.</li></ul>
<h3>Open ideas</h3>
<ul><li>A probe for <code>clearElementGeometry()</code>, <code>moveBefore()</code> in one task, and a nested drawable repainted outside the window.</li>
<li>A probe for the two alpha conventions that reads one half transparent box back through <code>texElementSubImage2D()</code> and through <code>drawElementImageToTexture()</code>. It needs a GPU context, so it would wait for its own tap.</li>
<li>A column for the tracker link once an entry is filed.</li></ul>
<p><a href="https://html-in-canvas.page/friction/">Open Friction log: where the API did not do what I expected</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A DOM form on a quad in a Godot 4 scene</title>
<link>https://html-in-canvas.page/godot-dom/</link>
<guid isPermaLink="true">https://html-in-canvas.page/godot-dom/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Godot</category>
<category>WebAssembly</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>A Godot 4.7 web export whose central quad shows a real login form and chat box. The browser paints the form into Godot's own WebGL texture and handles typing, focus and taps where Godot drew it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/godot-dom/"><img src="https://html-in-canvas.page/godot-dom/social.jpg" width="1200" height="630" alt="The page &quot;A DOM form on a quad in a Godot 4 scene&quot;"></a></p>
<p><strong>Question:</strong> Can a Godot 4 web export show a live DOM form on a quad in a 3D scene, with the browser handling typing, focus and clicks on the real fields where Godot drew them?</p>
<p><strong>Short answer:</strong> Yes in headless Chromium 157, with a stock Godot 4.7.2 export, one GDScript file and a JavaScript bridge. Three routes to the texture were built and all three draw the form. Not run on a phone.</p>
<p>
Godot is a game engine. Its web export draws everything into one WebGL canvas, so a login form or a chat box has to be rebuilt from engine controls,
and on a phone the keyboard only opens for a real <code>&lt;input&gt;</code>. Here the form is a real <code>&lt;form&gt;</code> inside Godot's canvas.
The browser paints it into a texture that Godot puts on a quad in a 3D scene. Load the engine, then type in the fields, press Sign in and send a chat line.
A press outside the form goes to Godot and recolours the orbiting objects.
</p>
<h3>How it works</h3>
<ul>
<li>The page gives Godot a canvas that already holds the form (<code>content="drawable"</code>, <code>layoutsubtree</code>, and <code>drawable</code> on the form). Godot makes its WebGL2 context on that canvas.</li>
<li>GDScript makes an <code>ImageTexture</code> of the size <code>getElementImageDefaultSize()</code> reports and asks <code>RenderingServer.texture_get_native_handle()</code> for its GL texture name. Emscripten maps names to <code>WebGLTexture</code> objects in <code>GL.textures</code>.</li>
<li>After each <code>paint</code> event, GDScript's <code>_process()</code> calls the bridge, which binds that texture and calls <code>gl.texElementSubImage2D()</code>, then puts Godot's binding back.</li>
<li>Each frame GDScript projects the quad's four corners with <code>Camera3D.unproject_position()</code>. The bridge turns them into a homography and passes it to <code>canvas.updateElementGeometry()</code>.</li>
<li>The form stops mouse, touch and key events from bubbling to the canvas, where Godot listens.</li>
<li>The route buttons switch how the texture is reached while the scene runs. "createTexture hook" records the texture Godot creates between two calls. "readPixels" uploads into a texture the page owns, reads it back with <code>readPixels()</code> and gives Godot the bytes.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21 with Godot 4.7.2 and software WebGL2, at 1× and at a 2.625 device scale with touch. Nothing here was run on a phone.</p>
<ul>
<li><strong>A stock Godot 4.7.2 web export drew a live DOM form on a quad.</strong> No engine change, no GDExtension and no custom export template. The scene is one GDScript file.</li>
<li><strong><code>GL.textures</code> is reachable from GDScript and not from the page.</strong> <code>JavaScriptBridge.eval(code, false)</code> runs a direct <code>eval</code> inside the engine's module function, where Emscripten's <code>GL</code> is a local variable. The same expression with <code>use_global_execution_context</code> true finds no <code>GL</code>. <code>get_interface("GL")</code> and <code>get_interface("Module")</code> return null, and the page's <code>Engine</code> object doesn't expose <code>GL</code> either.</li>
<li><strong><code>RenderingServer.texture_get_native_handle()</code> gave a usable GL name.</strong> <code>texElementSubImage2D()</code> wrote into the texture Godot had allocated with its own <code>glTexImage2D</code>. Row 0 of the element image is the top of the form, which is also Godot's convention, so there's no flip.</li>
<li><strong>The texture can be found without Emscripten.</strong> Godot creates exactly one WebGL texture while <code>ImageTexture.create_from_image()</code> runs, so a wrapper around <code>gl.createTexture</code> for the length of that call identifies it.</li>
<li><strong>The read-back route works and costs a <code>readPixels()</code> per repaint.</strong> It needs neither <code>GL.textures</code> nor a hook: <code>JavaScriptBridge.js_buffer_to_packed_byte_array()</code> turns the page's <code>Uint8Array</code> into an <code>Image</code>. The live checks report the time each route spent in its upload call on this device.</li>
<li><strong>The browser's GL can build the mip chain.</strong> The <code>Image</code> is created with mipmaps so that Godot samples with a mipmap filter, and the bridge calls <code>generateMipmap()</code> after each upload.</li>
<li><strong>One perspective matrix placed the hit box on the swaying quad.</strong> The check compares the box the browser reports for the form with the corners Godot projected.</li>
<li><strong>Godot's mouse handler takes focus.</strong> Its <code>mousedown</code> listener on the canvas calls <code>canvas.focus()</code>. A press on a field bubbles to the canvas. Without <code>stopPropagation()</code> at the form, focus was on the canvas after the click and typed text didn't reach the field. Godot also listens for <code>mouseup</code> and <code>paste</code> on the window.</li>
<li><strong>Godot doesn't know the form is there and the browser doesn't know what Godot draws over it.</strong> An orbiting object that passes in front of a field hides it, and a press on that spot still reaches the field. Hit testing follows the geometry only.</li>
<li><strong>The wasm file is over Cloudflare's 25 MiB limit for one static asset.</strong> <code>index.wasm</code> is 39.5 MB. It's stored as <code>index.wasm.gz</code> (10.1 MB), inflated with <code>DecompressionStream</code>, and handed to the engine by answering its <code>fetch()</code> with a <code>Response</code> of type <code>application/wasm</code>, which still compiles while streaming.</li>
<li><strong><code>get_interface()</code> on a missing name prints an engine error</strong> to the console as well as returning null.</li>
<li><strong>Not verified on a phone:</strong> the on-screen keyboard, IME composition, autofill, password managers, touch selection handles, screen readers, frame rate on a real GPU and the deployed site. The live checks run on the device that opens the page.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/godot-dom.md">findings/godot-dom.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157, HeadlessChrome/157.0.8103.78, software WebGL2) on 2026-11-21, at 1× and at a 2.625 device scale in a 412 px wide window with touch. Godot 4.7.2-stable, official web export template <code>web_nothreads_release</code> (Emscripten 4.0.20, single-threaded, no GDExtension), Compatibility renderer. Sources in <code>native/godot-dom/</code>, bridge in <code>public/godot-dom/bridge.js</code>. "Live check" means a row of the page's Live checks table, which runs on a framed copy of the app. "Script" means a Playwright script run against <code>fixture.html</code> or the page.</p>
<h3>Drawing the form</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A stock Godot 4.7.2 web export draws a live <code>&lt;form&gt;</code> on a <code>MeshInstance3D</code> quad</td><td>works (measured, live check)</td><td>The form is a <code>drawable</code> child of the canvas Godot is given. A pixel read back from Godot's frame at the place the browser reports for the form's blue band is rgb(29,79,191) for CSS <code>#1f4fbf</code>, and rgb(208,12,154) after the band is restyled to <code>#d0109a</code>.</td></tr>
<tr><td>Route 1: <code>RenderingServer.texture_get_native_handle()</code> gives the GL name, <code>GL.textures[name]</code> gives the <code>WebGLTexture</code>, <code>gl.texElementSubImage2D()</code> writes into it</td><td>works (measured, live check)</td><td>Name 1012 in every run. Godot allocated the texture itself (RGBA8, with a mip chain). Upload call 1.5 ms at 300×397 texels, 10 to 21 ms at 788×1037 (software GL).</td></tr>
<tr><td><code>JavaScriptBridge.eval(code, false)</code> sees Emscripten's <code>GL</code></td><td>yes (measured, live check)</td><td>The engine runs a direct <code>eval</code> inside its module function, where <code>GL</code> is a local variable.</td></tr>
<tr><td><code>JavaScriptBridge.eval(code, true)</code> sees <code>GL</code></td><td>no (measured, live check)</td><td>Global scope.</td></tr>
<tr><td><code>JavaScriptBridge.get_interface("GL")</code>, <code>get_interface("Module")</code></td><td>null (measured, live check)</td><td><code>get_interface()</code> reads a property of the global object. Each failed call also prints an engine error to the console.</td></tr>
<tr><td><code>engine.rtenv.GL</code> from page script, with the engine's <code>Engine</code> loader and no HTML shell</td><td>not there (measured, live check)</td><td><code>GL</code> is not exported from the module, so a custom shell that captures the module would not find it either (inferred from the same measurement).</td></tr>
<tr><td>Route 2: wrap <code>gl.createTexture</code> while <code>ImageTexture.create_from_image()</code> runs and keep the texture created</td><td>works (measured, live check)</td><td>Exactly 1 texture is created during the call. No Emscripten internals. Upload call 4 to 10 ms. Depends on Godot creating the GL texture during the call, which the single-threaded build does.</td></tr>
<tr><td>Route 3: upload into a texture the page owns, <code>readPixels()</code> through a framebuffer, <code>js_buffer_to_packed_byte_array()</code>, <code>Image.create_from_data()</code>, <code>ImageTexture.update()</code></td><td>works (measured, live check)</td><td>Upload and read-back 1.7 ms at 300×397 and 15 to 25 ms at 788×1037, before Godot's own copy of the bytes into its heap and back to GL, which was not timed. No mip chain on this route.</td></tr>
<tr><td>A second 2D drawable canvas that holds the form, with pixels passed to Godot</td><td>not built</td><td>Route 3 gets the same pixels from the one canvas, and the form has to stay in Godot's canvas for <code>updateElementGeometry()</code> to place it there.</td></tr>
<tr><td>Row order</td><td>no flip (measured, screenshots)</td><td>Row 0 of the element image is the top of the form, and Godot's UV origin is the top left.</td></tr>
<tr><td>Mipmaps</td><td>works (measured, screenshots)</td><td>The <code>Image</code> is created with mipmaps so Godot uses a mipmap filter; the bridge calls <code>gl.generateMipmap()</code> after each upload. Text is legible on the tilted quad at 1× and 2.625×.</td></tr>
<tr><td><code>content="drawable"</code> and <code>layoutsubtree</code> on the canvas before Godot creates its WebGL2 context</td><td>works (measured)</td><td>Godot's <code>getContext()</code> on that canvas succeeded.</td></tr>
<tr><td>GL state after the bridge's calls</td><td>no visible damage (measured, screenshots)</td><td>The bridge saves and restores <code>ACTIVE_TEXTURE</code>, <code>TEXTURE_BINDING_2D</code> and the framebuffer binding. Not tested without the restore.</td></tr></tbody></table>
<h3>Input</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Hit box on the swaying quad from one perspective matrix</td><td>works (measured, live check)</td><td><code>Camera3D.unproject_position()</code> for the four corners, a homography in a <code>DOMMatrix</code>, <code>updateElementGeometry()</code>. The browser's box for the form is within 0.2 to 0.3 px of the bounds of Godot's corners. <code>elementFromPoint()</code> at the email field returns the <code>&lt;input&gt;</code>. Unit of <code>canvasTransform</code>: CSS px (1.00) at both scales.</td></tr>
<tr><td>Click a field, type, Tab, Enter</td><td>works (measured, script, 1×)</td><td>Click on email focuses <code>input[email]</code>. Tab moves to the password field. Enter submits the form. Typing shows on the quad (screenshot). A click 14 px from the left edge of a filled field put the caret before the first character.</td></tr>
<tr><td>Touch at 2.625×</td><td>works (measured, script, CDP touch events)</td><td>A tap on the password field and on the textarea focuses each. A tap on Send posts the chat line. The page did not scroll.</td></tr>
<tr><td>Form to Godot</td><td>works (measured, live check)</td><td>The submit handler calls a GDScript function made with <code>JavaScriptBridge.create_callback()</code>. A <code>Label3D</code> shows the email or the chat line.</td></tr>
<tr><td>A press on a field with the event guard</td><td>Godot gets nothing (measured, live check and script)</td><td>The form calls <code>stopPropagation()</code> for mouse, pointer, touch, key, wheel and paste events. Godot's press count stays at 0.</td></tr>
<tr><td>A press on a field without the guard (<code>fixture.html?focus=1&amp;bubble=1</code>)</td><td>the field loses focus (measured, script)</td><td>Godot's <code>mousedown</code> listener on the canvas calls <code>canvas.focus()</code>. After the click <code>document.activeElement</code> is the canvas, Godot counted 1 press, and typing "abc" left the field empty.</td></tr>
<tr><td>A press on the canvas beside the form</td><td>goes to Godot (measured, live check and script)</td><td>Godot counts it and focuses the canvas, so the field blurs.</td></tr>
<tr><td>Occlusion by Godot's own objects</td><td>not handled, not measured</td><td>An orbiting object drawn in front of a field is not known to the browser. Hit testing uses the geometry only, as on <code>/native-ui/</code> and <code>/three-form/</code>.</td></tr></tbody></table>
<h3>Packaging</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Size of the export</td><td>measured</td><td><code>index.wasm</code> 39,514,754 bytes, <code>index.js</code> 279,815, <code>index.pck</code> 13,168, two audio worklets 10,271.</td></tr>
<tr><td><code>index.wasm</code> as a static asset on Cloudflare Workers</td><td>too large</td><td>The limit is 25 MiB per file.</td></tr>
<tr><td>Commit <code>index.wasm.gz</code> (gzip -9, 10,084,286 bytes), inflate with <code>DecompressionStream('gzip')</code>, answer the engine's <code>fetch()</code> of <code>index.wasm</code> with a <code>Response</code> of type <code>application/wasm</code></td><td>works (measured, live check, localhost)</td><td>The engine's <code>WebAssembly.instantiateStreaming()</code> accepted the stream. Running 2.1 to 3.2 s after the start of the download. It is one file under the limit, so the file was not split into parts. Committed build output 10.4 MB in total.</td></tr>
<tr><td>Godot's <code>Engine</code> loader without its HTML shell</td><td>works (measured)</td><td><code>new Engine({ canvas, executable, mainPack, canvasResizePolicy: 0, focusCanvas: false })</code>, then <code>startGame()</code>. The page sizes the canvas buffer and Godot follows it.</td></tr>
<tr><td><code>npm run check:jank -- /godot-dom/</code> and with <code>--checks</code></td><td>pass (measured)</td><td>With <code>--checks</code> at 4× CPU throttle the checks finish in 18 s, with 14.7 s of long tasks while the engine compiles and starts in the fixture frame. The page keeps <code>&lt;meta name="checks" content="tap"&gt;</code> because the checks download 10.4 MB.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Godot's <code>mousedown</code> listener focuses the canvas. Without the guard a click on a field left focus on the canvas.</li>
<li>Inside the check fixture's frame, that same <code>canvas.focus()</code> could move focus out of the page that runs the checks. The fixture replaces <code>focus</code> on its canvas with a function that does nothing.</li>
<li><code>JavaScriptBridge.eval()</code> gave GDScript 1 and 0 for JavaScript booleans. The script wraps the result in <code>bool()</code>.</li>
<li><code>get_interface()</code> on a missing global prints <code>at: get_interface (platform/web/javascript_bridge_singleton.cpp:305)</code> through the engine's error printer. The bridge keeps engine errors apart from its own upload errors.</li>
<li>The engine's loader has no option that takes a <code>Response</code> or bytes for the wasm. The bridge replaces <code>window.fetch</code> until <code>startGame()</code> resolves and puts it back.</li>
<li>To check what Godot drew, the checks call <code>gl.readPixels()</code> on the default framebuffer from a <code>requestAnimationFrame</code> callback, which runs after Godot's own callback in the same frame. The drawing buffer is not preserved after that.</li>
<li>A torus placed near the panel swung through it. Objects that must stay behind the form are placed well behind it.</li></ul>
<h3>Not verified</h3>
<ul><li>A real phone. The on-screen keyboard, IME composition, autofill and password managers on the fields, touch selection handles and the magnifier were not run. Open <code>/godot-dom/</code> on the phone, load the app, tap each field and type.</li>
<li>Chrome 159 on Android, which the project owner's phone runs.</li>
<li>Frame rate and upload cost on a real GPU. The page prints the last upload time under the stage, and the live checks print it for each route.</li>
<li>The deployed site. <code>index.wasm.gz</code> was served by <code>python3 -m http.server</code> and the jank guard's server, which send no <code>Content-Encoding</code>. If a host sends <code>Content-Encoding: gzip</code> the browser inflates the file first. The bridge checks the first two bytes and skips its own inflate in that case. That branch was not run.</li>
<li>Loss of the WebGL context. The page shows a message on <code>webglcontextlost</code>. The event was not forced, because <code>WEBGL_lose_context.loseContext()</code> on a drawable WebGL canvas crashes the renderer in C157.</li>
<li>Screen readers. The check only reads <code>computedName</code> or the label text.</li>
<li>Godot's threaded build, the <code>dlink</code> templates and the debug template. Route 2 assumes the GL texture is created during the <code>create_from_image()</code> call, which a threaded rendering server may not do.</li>
<li>Occlusion: turning a press away from a field that is under an orbiting object, for example with a ray cast in GDScript before the event is delivered.</li>
<li>Transparent forms. The quad's shader ignores alpha and the upload is not premultiplied.</li></ul>
<p><a href="https://html-in-canvas.page/godot-dom/">Open A DOM form on a quad in a Godot 4 scene</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A video as a WebGPU external texture under HTML cards</title>
<link>https://html-in-canvas.page/gpu-video/</link>
<guid isPermaLink="true">https://html-in-canvas.page/gpu-video/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>importExternalTexture</category>
<category>drawElementImageToTexture</category>
<category>texture_external</category>
<category>WebGPU</category>
<description>One shader pass samples a video frame and two HTML cards as separate textures. The cards are glass that bends the frame. A button times each way of getting the frame and the HTML to the GPU.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/gpu-video/"><img src="https://html-in-canvas.page/gpu-video/social.jpg" width="1200" height="630" alt="The page &quot;A video as a WebGPU external texture under HTML cards&quot;"></a></p>
<p><strong>Question:</strong> Can one WebGPU render pass sample a video as a GPUExternalTexture and DOM elements as element textures, and what does that cost per frame compared with putting the video inside the drawn element?</p>
<p><strong>Short answer:</strong> The pass works with the frame copied into a texture. importExternalTexture() failed on the software adapter of the test browser, so the external texture and the costs on a real GPU are measured by the page on the device that opens it.</p>
<p>
The two cards below are HTML. The video frame behind them is a separate texture, and one shader pass draws all three: the cards are glass that bends and blurs the frame.
Type in the field, press the buttons, change the effect and tap the picture. "Measure on this device" times each way of getting the frame and the cards to the GPU.
</p>
<h3>How it works</h3>
<ul>
<li>The canvas has three children. Two are <code>drawable</code> cards. The third is the <code>&lt;video&gt;</code>, which has no <code>drawable</code> ancestor, so it's never part of an element's picture.</li>
<li>On WebGPU, <code>device.importExternalTexture({ source: video })</code> gives the current frame as a <code>GPUExternalTexture</code> with no copy. <code>queue.drawElementImageToTexture()</code> puts each card in an <code>rgba8unorm</code> texture. One fragment shader samples the frame with <code>textureSampleBaseClampToEdge()</code> and the cards with <code>textureSampleLevel()</code>.</li>
<li>If the import fails, the frame is copied with <code>queue.copyExternalImageToTexture()</code> and the same shader is compiled with <code>texture_2d&lt;f32&gt;</code> for the video.</li>
<li>On WebGL 2 the frame comes from <code>texImage2D(video)</code> and the cards from <code>texElementSubImage2D()</code>. On a 2D canvas the page uses <code>drawImage(video)</code>, <code>drawElementImage()</code>, <code>ctx.filter</code> and compositing modes. The 2D route has no ripple.</li>
<li>The page tries WebGPU, then WebGL 2, then 2D. The line under the picture names the route in use and gives the reason when it isn't WebGPU.</li>
<li>A shader draw doesn't place an element for hit testing. CSS <code>left</code> and <code>top</code> don't move a canvas child either. The page keeps each card's position, gives it to the shader as a rectangle, and gives it to <code>updateElementGeometry()</code> as a translation. It then toggles an attribute on the card.</li>
<li>The measurement compares this arrangement with the one <a href="https://html-in-canvas.page/video/">/video/</a> and <a href="https://html-in-canvas.page/overlay/">/overlay/</a> use, where the video is a child of the drawn element and one upload carries the frame and the HTML together.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless with a software WebGPU adapter (SwiftShader) and software video decoding, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: the pass itself.</strong> One WebGPU render pass samples a video texture and two element textures. The frame number in the composed picture and the colours of the cards were read back from the target texture.</li>
<li><strong>Fails here: <code>importExternalTexture()</code>.</strong> With the software adapter it throws "Failed to import texture from video" for a <code>&lt;video&gt;</code> and for a <code>VideoFrame</code>. <code>copyExternalImageToTexture(video)</code> also throws in Chromium 157 with this adapter. <code>createImageBitmap(video)</code> followed by <code>copyExternalImageToTexture(bitmap)</code> works, and the checks fall back to it. So the <code>texture_external</code> shader variant compiled here but didn't draw. The first, third and eighth checks answer this on a device with a real GPU.</li>
<li><strong>Works: the video inside the element.</strong> An element that contains a playing <code>&lt;video&gt;</code> uploads with <code>drawElementImageToTexture()</code> and its texture holds a frame.</li>
<li><strong>Works: the same picture on WebGL 2.</strong> The GLSL and WGSL shaders were compared on a paused frame for all three effects. The differences are in the fifth check.</li>
<li><strong>Needed: a translation in <code>canvasTransform</code>.</strong> A canvas child with <code>left: 200px; top: 100px</code> has its box at the canvas origin, and percentages in <code>left</code>, <code>right</code> and <code>bottom</code> gave a box 0 px wide. With an identity matrix the card is hit tested at the origin. <code>new DOMMatrix().translate(200, 100)</code>, in CSS pixels, puts the hit box where the shader draws the card.</li>
<li><strong>Needed: multiply by alpha in the shader.</strong> In these textures a box with <code>rgb(200 100 50 / .5)</code> is stored as 199, 100, 50 with alpha 0.5, on WebGPU and on WebGL 2. Adding the texture's colour to the frame without multiplying it turned every translucent control white.</li>
<li><strong>Refused: an element as an external texture.</strong> <code>importExternalTexture({ source: element })</code> throws a <code>TypeError</code>. An element reaches WebGPU only through the copy in <code>drawElementImageToTexture()</code>.</li>
<li><strong>Not verified here:</strong> WebGPU on screen, <code>importExternalTexture()</code> with a hardware decoder, whether the external texture expires, and every timing on a real GPU. The "Measure on this device" button and the live checks report these on the device that opens the page.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/gpu-video.md">findings/gpu-video.md</a> in the repository.</p>
<p>Chromium 157 headless (157.0.8103.78), software rendering and software video decoding, 2026-11-21. Every WebGPU row was measured with the SwiftShader software adapter (<code>--enable-unsafe-webgpu --enable-unsafe-swiftshader</code>), off screen: the pass draws into a texture that is read back. The default headless launch has no WebGPU adapter, and there only the 2D check runs. WebGPU on screen is not verified.</p>
<p>The page draws two <code>drawable</code> HTML cards and a <code>&lt;video&gt;</code> in one shader pass. The video is a child of the canvas with no <code>drawable</code> ancestor. Routes in order: WebGPU (<code>importExternalTexture(video)</code>, else <code>copyExternalImageToTexture(video)</code>, plus <code>drawElementImageToTexture()</code> for each card), WebGL 2 (<code>texImage2D(video)</code> plus <code>texElementSubImage2D()</code>), 2D (<code>drawImage(video)</code> plus <code>drawElementImage()</code>). In the test browser the visible demo runs on WebGL 2 and the page says why WebGPU is not in use.</p>
<h3>The pass (live checks, software adapter)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>device.importExternalTexture({ source: video })</code></td><td>fails here</td><td><code>OperationError: Failed to import texture from video</code>. Same for a detached video, an attached one, inside <code>requestVideoFrameCallback()</code>, and with the launch flags <code>--enable-features=Vulkan --use-angle=swiftshader</code>, <code>--ignore-gpu-blocklist</code>, <code>--in-process-gpu</code>, <code>--enable-features=SkiaGraphite</code>. Same in the full Chromium 153 build. The <code>texture_external</code> variant of the shader compiled but drew nothing here.</td></tr>
<tr><td><code>importExternalTexture({ source: new VideoFrame(video) })</code></td><td>fails here</td><td>Same message. The frame is I420, coded size 704×360. A <code>VideoFrame</code> made from a canvas (BGRA) and from RGBA and I420 buffers failed the same way in a probe script.</td></tr>
<tr><td><code>queue.copyExternalImageToTexture({ source: video }, …)</code></td><td>fails here</td><td><code>Failed to copy content from video element.</code> in Chromium 157. In the full Chromium 153 build with the same adapter it worked for the video and for a <code>VideoFrame</code> (probe script, not a page check).</td></tr>
<tr><td><code>createImageBitmap(video)</code>, then <code>copyExternalImageToTexture({ source: bitmap }, …)</code></td><td>works</td><td>The route the checks fall back to. It is asynchronous.</td></tr>
<tr><td>One render pass sampling the frame texture and two element textures</td><td>works</td><td>Read back from a 320×180 <code>rgba8unorm</code> target: the clip's frame stripes, the card's colour 0, 200, 83 and a half transparent blue tag over the frame (126, 64, 250). The frame came through the bitmap route.</td></tr>
<tr><td>Frame in the composed picture against <code>requestVideoFrameCallback()</code> metadata</td><td>12 of 12 match</td><td>With the bitmap route, which resolves after the callback. At software speed the video presented about every fifth frame. Not measured for an external texture.</td></tr>
<tr><td>Using a <code>GPUExternalTexture</code> in a later task</td><td>not measured</td><td>The import fails here, so the row fails before the test.</td></tr>
<tr><td>An element that contains the playing video, <code>drawElementImageToTexture()</code></td><td>works</td><td>The texture holds the frame and the label over it. In 6 uploads, each in the first <code>paint</code> after a <code>requestVideoFrameCallback()</code>, the frame was the one the callback reported.</td></tr>
<tr><td>WGSL pass against the GLSL draw, video paused on frame 60</td><td>same picture</td><td>Mean difference 0.00 of 255 for glass, video inside the text and ripple. Largest difference 1. The WebGPU frame came through the bitmap route and the WebGL frame through <code>texImage2D(video)</code>.</td></tr>
<tr><td><code>importExternalTexture({ source: element })</code></td><td>refused</td><td><code>TypeError</code>: the source must be <code>HTMLVideoElement</code> or <code>VideoFrame</code>. Row marked <code>expect: 'fail'</code>.</td></tr>
<tr><td>2D route: <code>drawImage(video)</code> then <code>drawElementImage(card, x, y, w, h)</code></td><td>works</td><td>Measured with the default launch too. The button on the card is found by <code>elementFromPoint()</code> with no <code>updateElementGeometry()</code> call.</td></tr></tbody></table>
<h3>Layout and hit testing of canvas children</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>position: absolute; left: 200px; top: 100px</code> on a child of a <code>layoutsubtree</code> canvas</td><td>does not move it</td><td><code>getBoundingClientRect()</code> is at the canvas origin until a draw call or <code>updateElementGeometry()</code> places it. <code>offsetLeft</code> and <code>offsetTop</code> are -1. <code>offsetParent</code> is the canvas.</td></tr>
<tr><td><code>left: 3%; right: 3%; bottom: 5%</code> on a canvas child with no width</td><td>0 px wide</td><td>Percentages did not resolve against the canvas box. The page sets the card's width in pixels from <code>canvas.clientWidth</code> and keeps each card's position in script.</td></tr>
<tr><td>After a WebGPU pass alone, <code>elementFromPoint()</code> at the drawn button</td><td>the canvas</td><td></td></tr>
<tr><td><code>updateElementGeometry(card, { canvasTransform: new DOMMatrix() })</code></td><td>hit box at the canvas origin</td><td>Not at the drawn position.</td></tr>
<tr><td><code>canvasTransform: new DOMMatrix().translate(200, 100)</code> plus an attribute toggle</td><td>the button is hit where it is drawn</td><td>CSS pixels, with a 320 px wide canvas and a 320 px or 640 px buffer. <code>translate(400, 200)</code> missed.</td></tr>
<tr><td>Alpha of an element texture</td><td>straight, not premultiplied</td><td><code>rgb(200 100 50 / .5)</code> is stored as 199, 100, 50 and <code>rgb(0 0 255 / .5)</code> as 0, 0, 255, alpha 0.5, on WebGPU and WebGL 2. <code>FINDINGS.md</code> says "Pixels are premultiplied" for <code>drawElementImageToTexture()</code>. This page measured the opposite on translucent content, and its shaders multiply by alpha. The seventh live check reports which one a device does.</td></tr>
<tr><td>A <code>&lt;video&gt;</code> child of the canvas with no <code>drawable</code> ancestor</td><td>plays, is never painted</td><td><code>requestVideoFrameCallback()</code> fires. <code>texImage2D(video)</code> and <code>drawImage(video)</code> take its frames. Moving it to a new canvas that is already in the document does not pause it.</td></tr></tbody></table>
<h3>Cost per frame ("Measure on this device", software adapter and software GL)</h3>
<p>40 draws, one per presented video frame, plain shader, 640×360 target that is not shown. "calls" is CPU time inside the upload and draw calls. "done" runs until <code>onSubmittedWorkDone()</code> (WebGPU) or a one pixel <code>readPixels()</code> (WebGL, since replaced by <code>gl.finish()</code>). "pass" is the render pass from a <code>timestamp-query</code> query set on a second device. These numbers are from a software rasterizer and say nothing about a GPU.</p>
<table><thead><tr><th>Route</th><th>Uploaded each frame</th><th>calls</th><th>done</th><th>pass</th></tr></thead><tbody><tr><td>WebGPU, software</td><td><code>importExternalTexture(video)</code> + card texture</td><td>failed: import</td><td></td><td></td></tr>
<tr><td>WebGPU, software</td><td><code>importExternalTexture(video)</code>, card uploaded once</td><td>failed: import</td><td></td><td></td></tr>
<tr><td>WebGPU, software</td><td>element that contains the video (640×360), one <code>drawElementImageToTexture()</code></td><td>2.11 ms</td><td>68.39 ms</td><td>41.60 ms</td></tr>
<tr><td>WebGPU, software</td><td><code>copyExternalImageToTexture(video)</code> + card texture</td><td>failed: copy</td><td></td><td></td></tr>
<tr><td>WebGPU, software</td><td><code>createImageBitmap(video)</code>, <code>copyExternalImageToTexture(bitmap)</code> + card texture (200×120)</td><td>3.30 ms</td><td>69.74 ms</td><td>35.68 ms</td></tr>
<tr><td>WebGL 2</td><td><code>texImage2D(video)</code> + <code>texElementSubImage2D(card)</code></td><td>3.71 ms</td><td>26.83 ms</td><td></td></tr>
<tr><td>WebGL 2</td><td>element that contains the video, one <code>texElementSubImage2D()</code></td><td>2.37 ms</td><td>18.77 ms</td><td></td></tr>
<tr><td>2D</td><td><code>drawImage(video)</code> + <code>drawElementImage(card)</code></td><td>1.45 ms</td><td></td><td></td></tr>
<tr><td>2D</td><td>element that contains the video, one <code>drawElementImage()</code></td><td>0.03 ms</td><td></td><td></td></tr></tbody></table>
<p>The WebGL numbers moved between runs (done 26.83 to 43.47 ms for the first row, 18.77 to 49.78 ms for the second), so no order between the two arrangements can be read from them. The 2D calls only record the drawing, so their numbers leave out the rasterization. The adapter listed <code>timestamp-query</code>, and a device made with it gave pass times.</p>
<h3>Things that bit</h3>
<ul><li>Both cards were drawn in the top left corner at first. CSS <code>left</code>, <code>top</code> and percentages do nothing for a canvas child, and <code>offsetLeft</code> is -1. The page now computes positions and passes them to the shader and to <code>updateElementGeometry()</code>.</li>
<li>Every translucent control was drawn solid white. The element texture has straight alpha and the shader added its colour to the frame without multiplying. A check with a half transparent box over black found it.</li>
<li><code>requestDevice()</code> a second time on the same adapter throws <code>adapter is "consumed"</code>. An earlier version of the measurement made a second device with <code>timestamp-query</code> from a new adapter, and the pass times in the table come from it. The page now uses only the shared device, which has no <code>timestamp-query</code>, so the pass column reads "not timed".</li>
<li>A canvas keeps the kind of context it first gave, so changing route needs a new canvas. Moving the children to a clone that is not yet in the document pauses the video. The clone is inserted first and the children are moved after.</li>
<li><code>GPUElementTexture</code> textures have no <code>COPY_SRC</code> usage, so a check cannot read one directly. The checks draw it to a target and read that.</li>
<li>The two measured arrangements first used different shaders (glass against plain), which made "done" and "pass" measure the shader. Both now draw with the plain effect.</li></ul>
<h3>Not verified</h3>
<ul><li><code>importExternalTexture(video)</code> and <code>importExternalTexture(VideoFrame)</code> on a real GPU, with a hardware or a software decoder. Live checks 1 and 8 on the device.</li>
<li>Whether a <code>GPUExternalTexture</code> from a video is refused in a later task. Live check 3 reports the validation error or the frame it drew.</li>
<li>Frame accuracy of an external texture against <code>requestVideoFrameCallback()</code>. Live check 4.</li>
<li><code>copyExternalImageToTexture(video)</code> in Chrome 159. Live check 10.</li>
<li>The WebGPU route on screen: <code>GPUCanvas</code> presentation, the fallback to <code>copyExternalImageToTexture()</code> and to WebGL when the first frame has a validation error or is blank. None of that code ran in the test browser. Open the page on a device with WebGPU and read the line under the picture.</li>
<li>Every cost on a real GPU, and the comparison the experiment asked for (external texture plus card texture against the video inside the element). The "Measure on this device" button gives the table on the phone. Chrome quantizes timestamp queries to 100 µs unless developer features are on, so short passes will read 0.00 or 0.10 ms.</li>
<li>The live checks under the jank guard with a WebGPU adapter. <code>tools/jank/check.mjs --checks</code> uses the default launch, where the WebGPU rows stop at "no WebGPU device".</li>
<li>Typing with an on-screen keyboard, and touch on a real phone. Taps, the buttons and typing were driven by Playwright touch and key events at 412 px on the WebGL and 2D routes.</li></ul>
<h3>Open ideas</h3>
<ul><li>Run the measurement at the texture sizes of the visible demo on a phone (device pixel ratio 2.625 gives cards of about 1000×250).</li>
<li>The same pass with a camera <code>MediaStreamTrack</code> frame as the external texture.</li>
<li>A worker that owns the device and receives <code>VideoFrame</code>s and <code>ElementImage</code> snapshots.</li></ul>
<p><a href="https://html-in-canvas.page/gpu-video/">Open A video as a WebGPU external texture under HTML cards</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Live DOM on physical devices</title>
<link>https://html-in-canvas.page/hardware-out/</link>
<guid isPermaLink="true">https://html-in-canvas.page/hardware-out/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebHID</category>
<category>Web Serial</category>
<category>changedElements</category>
<category>getImageData</category>
<description>HTML buttons as the keys of a Stream Deck, an element printed by a receipt printer and a CSS ticker on an LED matrix. Each canvas is converted to the bytes its device accepts, and a simulated device is drawn from those bytes.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/hardware-out/"><img src="https://html-in-canvas.page/hardware-out/social.jpg" width="1200" height="630" alt="The page &quot;Live DOM on physical devices&quot;"></a></p>
<p><strong>Question:</strong> Can ordinary HTML be the interface of a device that isn't a browser window: a key pad with a display in each key, a receipt printer, an LED matrix?</p>
<p><strong>Short answer:</strong> Yes as far as the bytes: three canvases are converted to HID reports, ESC/POS and RGB565, and simulated devices are drawn from them. No real device has been tried.</p>
<p>
A canvas that draws HTML can also hand its pixels to a device that isn't a screen in a browser window. I wanted to know whether ordinary
HTML can be the interface of three such devices: a key pad with a small display in every key, a receipt printer and an LED matrix sign.
The three canvases below hold a small shop till. Each is converted to the bytes its device accepts, and a simulated device next to it is
drawn from those bytes. Press the keys of the simulated key pad: each press clicks the HTML button it shows.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Ordinary HTML works as the interface of all three devices, as far as bytes go.</strong> The buttons, the receipt and the sign are elements with CSS. Nothing in them is written for the device. The conversion code is about 200 lines for the three formats.</li>
<li><strong>A grandchild of the canvas with the <code>drawable</code> attribute can be drawn by itself.</strong> The fifteen buttons sit in a grid inside one child of the canvas. Each is drawn with its own <code>drawElementImage()</code> call into a square of a different size than its layout box.</li>
<li><strong><code>event.changedElements</code> names the keys to refresh.</strong> A device with fifteen separate displays needs to know which of them changed. The <code>paint</code> event lists the drawable buttons whose rendering was invalidated: a frame of the animated key lists that button only, and a clock tick lists the clock. The list isn't a pixel comparison. Setting a button's text to the value it already has puts it on the list, so adding one item listed all three item keys. The page hashes the pixels of each listed key and sends only those that differ from what was last sent.</li>
<li><strong>A CSS animation inside a canvas child fires <code>paint</code> on every frame with no script.</strong> The ticker has no timer and no <code>requestPaint()</code>. The page limits the matrix to 30 frames a second and the key pad to 10 updates a second.</li>
<li><strong>A physical key press can only be a synthetic click.</strong> The page calls <code>click()</code> on the button. That runs its handlers, but the event isn't trusted, there's no <code>:active</code> state and no focus change. The page adds a class while a key is held so that the key picture shows the press.</li>
<li><strong>Text for one-bit paper should be styled for it.</strong> The printer has no grey. Anti-aliased text edges become scattered dots under error diffusion and get thinner under a threshold. Heavier type and black on white print cleanly. The gradient bar in the receipt shows what each method does with grey.</li>
<li><strong>The printed picture includes the caret.</strong> The name field in the receipt is a real <code>&lt;input&gt;</code>. If it has focus when "Print" is pressed, the blinking caret is in the canvas and can be printed as a vertical line after the name. Placeholder text is printed too. A page that prints forms should blur the field and hide placeholders first.</li>
<li><strong>Serial ports are slow for frames.</strong> A 64 × 32 RGB565 frame is 4,100 bytes. At 115,200 baud that is about 2.8 frames a second, and at 921,600 about 22. The page drops frames while the port is busy.</li>
<li><strong>Not verified on hardware.</strong> Every result above is from the simulated devices in Chromium 157. The WebHID and Web Serial calls were only checked for existing. Whether a real device accepts these bytes isn't known.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/fold.md">findings/fold.md</a> in the repository.</p>
<h3><code>/hardware-out/</code>, <code>lib/device-out.js</code></h3>
<p>Three canvases hold a shop till written as plain HTML: fifteen buttons, a receipt, a sign. Each is converted to the bytes of a device, and a simulated device on the page is drawn from those bytes by a reader that knows nothing about the DOM.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Fifteen <code>&lt;button drawable&gt;</code> grandchildren of one canvas, each drawn into its own 72 x 72 square</td><td>works</td><td><code>drawElementImage(button, x, y, 72, 72)</code> per button. The buttons stay clickable in the canvas at the drawn size.</td></tr>
<tr><td><code>event.changedElements</code> to choose which keys to refresh</td><td>works, over-reports</td><td>A frame of an animated key lists that button only. Setting text to the same value also lists the element, so the page hashes the pixels of listed keys before sending.</td></tr>
<tr><td>Key picture to JPEG to 1,024-byte HID reports and back</td><td>works</td><td><code>OffscreenCanvas.convertToBlob()</code> per key, about 1.2 KB and 2 reports. The reader returns the same bytes. Report layout is that of the 15-key JPEG Stream Decks.</td></tr>
<tr><td>A key press from the device</td><td>synthetic only</td><td>The input report leads to <code>button.click()</code>. Handlers run. The event is not trusted and there is no <code>:active</code>.</td></tr>
<tr><td>An element as ESC/POS raster (<code>GS v 0</code>)</td><td>works</td><td>384 dots wide, about 15 KB for a 330 row receipt. Error diffusion, an ordered pattern or a threshold. The reader gets the same dots back.</td></tr>
<tr><td>A focused <code>&lt;input&gt;</code> in the printed element</td><td>caret is printed</td><td>The caret and the placeholder are part of the picture.</td></tr>
<tr><td>A CSS <code>@keyframes</code> ticker drawn into 64 x 32 pixels</td><td>works</td><td><code>paint</code> fires about 60 times a second with no script, also while the canvas is scrolled out of view. Frames are RGB565, 4,100 bytes.</td></tr></tbody></table>
<p>Not verified: any device. WebHID and Web Serial exist in the test browser, Web Bluetooth does not. The Stream Deck report layout comes from open-source drivers. The LED matrix frame format is this page's own and needs firmware written for it.</p>
<p><a href="https://html-in-canvas.page/hardware-out/">Open Live DOM on physical devices</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>HDR interface: elements brighter than white</title>
<link>https://html-in-canvas.page/hdr-glow/</link>
<guid isPermaLink="true">https://html-in-canvas.page/hdr-glow/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>float16 canvas</category>
<category>display-p3</category>
<category>HDR</category>
<category>dynamic-range-limit</category>
<description>A panel drawn into a 16-bit float canvas. A badge, a focus ring and a progress bar take values above standard white from CSS colours, and the canvas multiplies a button and a dot after drawing them. Views show the extra range on a standard screen.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/hdr-glow/"><img src="https://html-in-canvas.page/hdr-glow/social.jpg" width="1200" height="630" alt="The page &quot;HDR interface: elements brighter than white&quot;"></a></p>
<p><strong>Question:</strong> Do CSS colour values above 1.0 survive <code>drawElementImage()</code> into a float16 canvas, and which canvas operations and graphics routes keep them?</p>
<p><strong>Short answer:</strong> In a float16 Display P3 2D canvas, CSS colours above 1.0 read back unchanged, including box-shadow blur. multiply fills and fill shadows keep them; lighter, ctx.filter, CSS filter and drawImage() clamp to 1.0. WebGL and WebGPU element copies clamp to 1.0. On Chrome 159 on an Android phone the 2D canvas showed no extra brightness; a WebGPU rgba16float canvas with a shader that raises the uploaded element is the second route.</p>
<p>
The panel is HTML drawn into a 2D canvas whose pixels are 16-bit floats in Display P3. In that canvas 1.0 is standard white and a value above 1.0 is brighter than white on an HDR screen.
The badge, the focus ring and the end of the progress bar get their values from CSS colours with components above 1.0. The <b>Deploy</b> button and the green dot are ordinary sRGB colours
that the canvas multiplies after it has drawn them. Press <b>Deploy</b>, tab to the text field, and move the headroom slider.
</p>
<h3>How it works</h3>
<p>The canvas context is created with <code>colorType: 'float16'</code> and <code>colorSpace: 'display-p3'</code>. <code>drawElementImage()</code> then keeps CSS colour values above 1.0 that
the element's own styles ask for. The page uses two routes to get such values, because each has limits.</p>
<p><b>CSS route.</b> The badge, the focus ring, the bar and the strip use <code>color(display-p3 …)</code> with components multiplied by <code>--headroom</code>. The blur of a
<code>box-shadow</code> in such a colour also keeps its values, so the bloom around the badge is CSS. A CSS <code>filter</code> or <code>mix-blend-mode</code> on the element clamps it to 1.0.</p>
<p><b>Canvas route.</b> The Deploy button and the dot have sRGB colours. After the draw, the canvas fills their rounded boxes with a grey above 1.0 using the <code>multiply</code> operation,
which scales what is there. The halo is the shadow of an off-canvas fill. <code>lighter</code>, <code>ctx.filter</code> and a shadow on <code>drawElementImage()</code> itself all clamp to 1.0, so they aren't used.
The band of light after a deploy is one more <code>multiply</code> fill with a gradient.</p>
<p><b>Views.</b> A standard screen clips everything above 1.0 to white. "Exposed down" multiplies the whole canvas by 1 ÷ headroom, so the brightest value lands on white and the rest of the
panel goes dark in proportion. "Map" reads the float pixels back and colours each one: grey for 1.0 or under, yellow through red to magenta for 1.0 up to the headroom. The page picks
"As stored" when the screen reports <code>dynamic-range: high</code> and "Exposed down" otherwise.</p>
<p><b>WebGPU route.</b> "Use a WebGPU canvas" moves the panel into a canvas configured as <code>rgba16float</code>, Display P3, <code>toneMapping: { mode: 'extended' }</code>.
<code>drawElementImageToTexture()</code> stores at most 1.0, so the CSS colours are set back to headroom 1 and a shader does all the raising: it multiplies the boxes of the badge, the bar, the dot and
the Deploy button, raises the full-white pixels of the word in the strip, and adds the halos. The map view is drawn by the same shader, so it needs no readback. The focus ring isn't raised on this route.
The button is there because the 2D float canvas showed no extra brightness on my phone.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 a float16 Display P3 2D canvas keeps CSS colour values above 1.0 through <code>drawElementImage()</code>: backgrounds, text, borders, outlines, gradients,
<code>box-shadow</code> and <code>text-shadow</code> blur, and relative colours scaled with <code>calc()</code>. <code>color(display-p3 3 3 3)</code> reads back as 3.0.</li>
<li><code>color(srgb-linear 4 4 4)</code> reads back as 1.82 because the readback is in the canvas's encoded space: 4.0 linear is 1.82 after the sRGB transfer curve. It isn't a tone curve or a limit.</li>
<li><code>rgb()</code> and <code>oklch()</code> values above white clamp to 1.0. Only <code>color()</code> with a predefined space carried values above 1.0.</li>
<li>A CSS <code>filter</code> (even <code>blur(0)</code>) or <code>mix-blend-mode</code> on the element clamps its picture to 1.0. <code>opacity</code>, <code>mask</code>, <code>clip-path</code> and transforms do not.</li>
<li>On the canvas side, <code>source-over</code> and <code>multiply</code> fills, canvas gradients, shadows of fills and <code>putImageData()</code> keep values above 1.0. <code>lighter</code>, <code>screen</code>,
<code>ctx.filter</code>, a shadow on <code>drawElementImage()</code> and <code>drawImage()</code> of another float16 canvas clamp to 1.0. A bloom that blurs a copy of the canvas is therefore not possible in 2D.</li>
<li>WebGL and WebGPU don't receive the values. <code>texElementSubImage2D()</code> raises <code>INVALID_OPERATION</code> for an RGBA16F texture, and <code>drawElementImageToTexture()</code> into an
<code>rgba16float</code> texture stores 1.0 for a CSS value of 3.0. On those routes a shader has to decide which pixels to raise.</li>
<li><code>toneMapping: { mode: 'extended' }</code> is accepted by the 2D context and reported back as <code>standard</code> in Chromium 157 without the experimental features flag. The line under the controls prints what this browser reports.</li>
<li>On Chrome 159 on an Android phone, <code>getImageData()</code> with <code>pixelFormat: 'rgba-float16'</code> loses the float16 2D context, and every other float16 context on the page with it. The first version of the page read back every 1.5 seconds and was lost every 1.5 seconds. With readback on a button, the canvas was lost "right after a float readback" when the map view was chosen. Drawing alone didn't lose it. After such a loss the page now starts a new float16 canvas and switches readback and the map view off on that device.</li>
<li>That phone reports <code>dynamic-range: high</code>.</li>
<li>On that phone the word in this page's strip (15 pixel letters at 4.0 on 1.0) couldn't be read, with tone mapping <code>standard</code>, with <code>extended</code> (experimental features flag on) or with <code>dynamic-range-limit: no-limit</code>.</li>
<li>Values above 1.0 do reach that phone's screen through HTML-in-canvas. On <a href="https://html-in-canvas.page/hdr-glow/repro.html">the reduced case</a>, bars of 1.0 and 4.0 were seen in a plain float16 2D canvas, in a WebGPU canvas, in a drawable canvas drawn with <code>fillRect()</code>, and in a drawable canvas whose picture is an element drawn with <code>drawElementImage()</code>. A CSS white box beside them showed no bars. So the word that couldn't be read in this page's strip was a weak test, not a clamp: the strip now has bars as well.</li>
<li>A WebGPU canvas configured <code>rgba16float</code> with <code>toneMapping: { mode: 'extended' }</code> reports <code>extended</code> without a flag in Chromium 157. The page's shader raises an uploaded element to 4.0 in such a target (live check). Not verified: whether that route is shown brighter than white on the phone. "Use a WebGPU canvas" and the strip answer it on the device that opens the page.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/hdr-glow.md">findings/hdr-glow.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21. The test browser has no HDR output, so every result here is a value read back from the canvas with <code>getImageData(…, { pixelFormat: 'rgba-float16' })</code>, not something seen on a screen. Not yet run on the test phone.</p>
<p>The canvas in every row is a 2D context with <code>colorType: 'float16'</code> and <code>colorSpace: 'display-p3'</code>. Values are Display P3 component values as read back; 1.0 is standard white.</p>
<h3>CSS on the drawn element</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>background: color(display-p3 3 3 3)</code></td><td>3.0</td><td>Also through a border (2.5), an outline (3.0), text colour (3.0), <code>linear-gradient()</code> and <code>radial-gradient()</code> stops (4.0).</td></tr>
<tr><td><code>color(srgb-linear 4 4 4)</code></td><td>1.82</td><td>4.0 linear is 1.82 after the sRGB transfer curve, which Display P3 shares. The readback is encoded, so this is the same light as 4.0 linear. <code>color(srgb-linear 8 8 8)</code> reads 2.45. This answers the open question in the plan: it is not a tone curve or a limit.</td></tr>
<tr><td><code>color(srgb 2 2 2)</code>, <code>color(rec2100-linear 2 2 2)</code>, <code>color(xyz-d65 3 3 3)</code></td><td>2.0, 1.35, about 1.6</td><td>Each predefined space carries values above 1.0.</td></tr>
<tr><td><code>rgb(600 600 600)</code>, <code>oklch(2 0 0)</code></td><td>1.0</td><td>Clamped. Only <code>color()</code> carried values above white.</td></tr>
<tr><td>Relative colour <code>color(from #2a6cf0 display-p3 calc(r * var(--gain)) …)</code> with <code>--gain: 3</code></td><td>0.71, 1.25, 2.73</td><td>A custom property can scale an existing colour above 1.0.</td></tr>
<tr><td>The same colour with <code>--gain</code> animated by a CSS animation on a registered property</td><td>follows the animation</td><td>1.25 at the midpoint of 1 to 4 on mid grey.</td></tr>
<tr><td><code>box-shadow: 0 0 12px 6px color(display-p3 4 2 1)</code> in the blurred part</td><td>4, 2, 1 at alpha 0.27</td><td>The blur keeps the values (the readback is not premultiplied). <code>text-shadow</code> the same.</td></tr>
<tr><td><code>filter</code> on the element, including <code>blur(0px)</code> and <code>saturate(1)</code></td><td>1.0</td><td>Any CSS filter clamps the element's picture. <code>filter: drop-shadow()</code> in a colour of 4.0 gave 1.0.</td></tr>
<tr><td><code>mix-blend-mode: plus-lighter</code> on the element</td><td>1.0</td><td>Clamped.</td></tr>
<tr><td><code>opacity</code>, <code>mask</code>, <code>clip-path</code>, <code>border-radius</code>, <code>transform</code>, <code>will-change</code>, <code>backdrop-filter</code></td><td>3.0</td><td>Not clamped.</td></tr>
<tr><td><code>dynamic-range-limit: standard</code> on the element</td><td>3.0</td><td>The property does not change stored values. Its effect on the screen is not verified.</td></tr></tbody></table>
<h3>Canvas operations in the float16 context</h3>
<table><thead><tr><th>Operation</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>fillRect()</code> with <code>color(display-p3 3 3 3)</code>, canvas gradients, <code>putImageData()</code> of float data</td><td>keep values above 1.0</td><td></td></tr>
<tr><td><code>multiply</code> with a fill above 1.0 over drawn pixels</td><td>scales them, above 1.0</td><td>0.5 times 4 read back as 2.0. With a fill of 1 ÷ headroom it brings the whole canvas under 1.0. The page uses both.</td></tr>
<tr><td><code>source-over</code> with <code>globalAlpha</code></td><td>keeps</td><td>6.0 at half alpha over 2.0 gave 4.0.</td></tr>
<tr><td>Shadow of a fill (<code>shadowColor</code> above 1.0, <code>shadowBlur</code>)</td><td>keeps, 4.0</td><td>The page draws its halo this way, with the fill itself off the canvas.</td></tr>
<tr><td><code>lighter</code>, <code>screen</code>, <code>overlay</code>, <code>hard-light</code>, <code>color-dodge</code></td><td>clamp to 1.0</td><td>0.8 plus 0.8 with <code>lighter</code> is 1.0.</td></tr>
<tr><td><code>ctx.filter</code> (blur, brightness)</td><td>clamps to 1.0</td><td><code>brightness(3)</code> on white gives 1.0.</td></tr>
<tr><td><code>drawElementImage()</code> with <code>shadowBlur</code> set</td><td>element and shadow clamp to 1.0</td><td>The 3.0 element came out as 1.0.</td></tr>
<tr><td><code>drawElementImage()</code> with <code>globalAlpha</code>, a scale or a rotation</td><td>keeps 3.0</td><td></td></tr>
<tr><td><code>drawImage()</code> of a float16 canvas, an OffscreenCanvas or an ImageBitmap of one, and <code>createPattern()</code></td><td>clamp to 1.0</td><td>The source held 4.0. So a bloom that blurs a copy of the canvas cannot be built in 2D.</td></tr></tbody></table>
<h3>Other routes</h3>
<table><thead><tr><th>Route</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>WebGL 2: <code>texElementSubImage2D()</code> into <code>RGBA16F</code> or <code>RGBA32F</code> storage</td><td><code>INVALID_OPERATION</code></td><td><code>RGBA8</code> and <code>SRGB8_ALPHA8</code> are accepted and hold at most 1.0. <code>drawingBufferStorage(RGBA16F)</code> and <code>drawingBufferToneMapping()</code> exist, so a shader can write values above 1.0, but it does not receive them from the element.</td></tr>
<tr><td>WebGPU: <code>drawElementImageToTexture()</code> into <code>rgba16float</code></td><td>1.0 for a CSS value of 3.0</td><td>Measured with the SwiftShader adapter (<code>--enable-unsafe-webgpu</code>). With <code>colorSpace: 'display-p3'</code> on the destination the colours are converted and still clamped.</td></tr>
<tr><td><code>toneMapping: { mode: 'extended' }</code> on the 2D context</td><td>accepted; reported back as <code>standard</code></td><td>With <code>--enable-experimental-web-platform-features</code> it is reported as <code>extended</code>. A string instead of the dictionary throws a TypeError.</td></tr></tbody></table>
<h3>On the test phone (Chrome 159, Android), 2026-11-21</h3>
<p>Reported by the project owner with a screenshot of the first version of the page. Not reproduced in the test browser.</p>
<table><thead><tr><th>Observation</th><th>Detail</th></tr></thead><tbody><tr><td>The visible canvas was white with the context guard's note over it</td><td>"This canvas lost its 2D context and the page did not get it back."</td></tr>
<tr><td>The guard's log</td><td>10 2D contexts made, 1 WebGL, 1 WebGPU. 2D losses at 1.4 to 1.6 s, then seven at 3.1 s, seven at 4.6 s, seven at 6.1 s, seven at 7.6 s.</td></tr>
<tr><td>Which canvases</td><td>Seven matches the visible canvas plus the six float16 fixtures of the 2D live checks, which were out of the page but still alive. All float16 contexts were lost together.</td></tr>
<tr><td>The interval</td><td>1.5 s, which was the interval of the page's status readback (<code>getImageData()</code> with <code>pixelFormat: 'rgba-float16'</code>, four 1 by 1 reads). Chrome's own retry of a lost 2D context could give a similar rhythm, so the readback is suspected, not shown, as the cause.</td></tr>
<tr><td>The readback after the first loss</td><td>0.00 for every sample.</td></tr></tbody></table>
<p>Second report, same phone, after the readback became a button (PR 75): the panel was drawn and stayed until the map view was chosen. The page's notice then read "The float16 canvas lost its context on this device (right after a float readback with getImageData(), 5.3 s after load)". The screen line read "dynamic-range high, colour gamut srgb".</p>
<table><thead><tr><th>Result</th><th>Label</th></tr></thead><tbody><tr><td><code>getImageData()</code> with <code>pixelFormat: 'rgba-float16'</code> on a float16 Display P3 2D canvas loses that context, and the other float16 2D contexts on the page with it</td><td>reported, A159, twice: on a 1.5 s timer, and once on demand</td></tr>
<tr><td>Drawing elements into the float16 canvas with no readback does not lose it</td><td>reported, A159 ("it worked for a bit")</td></tr>
<tr><td>The phone's screen matches <code>(dynamic-range: high)</code></td><td>reported, A159</td></tr></tbody></table>
<p>Third report, same phone, on the preview of PR 82, 2026-11-21 17:47, asked to pick "As stored" and leave the map view alone: the word BRIGHTER in the white strip could not be read. It could be read after selecting the text of the strip, so the word was drawn and the selection highlight made it visible.</p>
<table><thead><tr><th>Result</th><th>Label</th></tr></thead><tbody><tr><td>A value of headroom times white in the canvas is shown at the same brightness as white: values above 1.0 do not appear brighter than white on this phone</td><td>reported, A159, once</td></tr></tbody></table>
<p>Fourth report, a screenshot at 18:03 on the same preview: "As stored", headroom 4.0, <code>dynamic-range-limit: no-limit</code>, 533 paint events, no readback pressed. The page's lines read "Screen: dynamic-range high, colour gamut srgb. Context: float16, display-p3, tone mapping standard." The white strip was blank. So the canvas was float16 and held the values, and the screen showed 4.0 times white as white.</p>
<table><thead><tr><th>Result</th><th>Label</th></tr></thead><tbody><tr><td>A float16 Display P3 2D canvas with tone mapping reported as <code>standard</code> shows values above 1.0 at the brightness of white, on a screen that matches <code>(dynamic-range: high)</code></td><td>reported, A159, with the context line in the screenshot</td></tr>
<tr><td><code>dynamic-range-limit: no-limit</code> on the canvas does not change that</td><td>reported, A159, same screenshot</td></tr></tbody></table>
<p>Fifth report, four screenshots at 19:57 on the same preview with chrome://flags "Experimental Web Platform features" turned on:</p>
<table><thead><tr><th>Observation</th><th>Label</th></tr></thead><tbody><tr><td>The context line reads "float16, display-p3, tone mapping extended". Without the flag it read "standard". So <code>getContext('2d', { toneMapping: { mode: 'extended' } })</code> is accepted on Chrome 159 Android only with the flag</td><td>reported, A159</td></tr>
<tr><td>The screen line is unchanged: dynamic-range high, colour gamut srgb</td><td>reported, A159</td></tr>
<tr><td>In the screenshot the white strip is blank. A screenshot is an SDR picture, so it cannot show whether the word was brighter than white on the screen itself. Not answered yet</td><td>not verified</td></tr>
<tr><td>The map view drew once (424 paint events): badge, Deploy button and its halo, bar, focus ring, heading and the first line of text are coloured as above 1.0. The strip is coloured only in its left third, with a stepped edge, while the canvas holds 4.0 across the whole strip</td><td>reported, A159. The cause of the partial strip is not known: a partial float readback is one explanation</td></tr>
<tr><td>A later float readback lost the context ("last seen right after a float readback with getImageData(), 32.3 s after load"). The panel moved to a new float16 canvas, which kept drawing (669 and 729 paint events) with tone mapping extended, and readback and the map were switched off</td><td>reported, A159. This is the first real run of the path that had only been tested with a dispatched event</td></tr>
<tr><td>So a float readback does not lose the context every time: at least one full-canvas readback returned data before the one that lost it</td><td>reported, A159</td></tr></tbody></table>
<p>Sixth report, 20:06, flag still on, "As stored", 62 paint events, context line "float16, display-p3, tone mapping extended": the word in the white strip could not be read on the screen itself.</p>
<table><thead><tr><th>Result</th><th>Label</th></tr></thead><tbody><tr><td>A float16 Display P3 2D canvas with tone mapping <code>extended</code> (flag on) also shows values above 1.0 at the brightness of white</td><td>reported, A159</td></tr>
<tr><td>So no setting of the 2D route tried here (tone mapping standard or extended, <code>dynamic-range-limit: no-limit</code>) showed extra brightness on this phone</td><td>reported, A159</td></tr></tbody></table>
<p>The partial strip in the map view of the fifth report is explained by the test browser: the halo of the Deploy button reaches the left part of the strip below it, and the halo is above 1.0 while the strip is 1.0. The WebGPU route's map drew the same shape in Chromium 157.</p>
<h3>The WebGPU route (added 2026-11-21 after the reports above)</h3>
<p>"Use a WebGPU canvas" moves the panel into a canvas configured <code>rgba16float</code>, <code>display-p3</code>, <code>toneMapping: { mode: 'extended' }</code>, with the device from <code>shared/backend.js</code>. The element is uploaded as an 8-bit picture and the shader in <code>public/hdr-glow/gpu-route.js</code> multiplies the boxes of the dot, the Deploy button, the badge and the bar, raises the full-white pixels of the word in the strip, adds halos, and draws the exposed and map views. No pixels are read back.</p>
<table><thead><tr><th>Result</th><th>Label</th></tr></thead><tbody><tr><td>The pass, drawn into an <code>rgba16float</code> texture: a white block with gain 4 reads back 4.00, the page beside it under 1.0</td><td>measured, live check, Chromium 157 headless (software adapter)</td></tr>
<tr><td><code>GPUCanvasContext.getConfiguration()</code> after configuring with <code>toneMapping: { mode: 'extended' }</code> reports <code>extended</code>, with no flag</td><td>measured, Chromium 157 headless</td></tr>
<tr><td>The whole panel through the route, with the canvas texture replaced by an off-screen texture in the test script: exposed and map views match the 2D route, the Hold button and the last line of the panel are hit at their places</td><td>measured by script, Chromium 157 headless</td></tr>
<tr><td>Presenting the canvas</td><td>not verified: a software adapter loses the device when it presents, so the button reports "the only WebGPU adapter is a software one" in the test browser. <code>?webgpu=force</code> skips that rule</td></tr>
<tr><td>On the test phone (Chrome 159, Android), 20:18, WebGPU route: "I faintly see it"</td><td>reported, A159, and not conclusive. In that version the strip was 248 and the word 255 before the shader, a 3 percent difference that can be faintly seen with no HDR at all. The strip is now 254, which cannot be told from 255, and the headroom slider gives the comparison: at 1.0 the word is not visible, and it should appear as the slider rises</td></tr></tbody></table>
<p>Seventh and eighth reports, 20:26 and 20:29, on <code>/hdr-glow/repro.html</code>: "1, 2 and 3 have bars", then "5 and 6 have the same bars. 4 has no bars".</p>
<table><thead><tr><th>Result</th><th>Label</th></tr></thead><tbody><tr><td>A plain float16 Display P3 2D canvas shows 4.0 brighter than 1.0</td><td>reported, A159</td></tr>
<tr><td>A WebGPU <code>rgba16float</code> canvas with tone mapping <code>extended</code> does too</td><td>reported, A159</td></tr>
<tr><td>A drawable float16 2D canvas does too, drawn with <code>fillRect()</code> and through <code>drawElementImage()</code> of an element with CSS colours at 4.0</td><td>reported, A159</td></tr></tbody></table>
<p>What the page does now: it reads floats back only when "Read values back" is pressed or the map view is chosen, and its live checks wait for a tap. When a float16 context is lost within 2.5 seconds of a readback, the panel moves into a new float16 canvas, and readback and the map view are switched off on that device (<code>localStorage</code>). When it is lost with no readback before, the new canvas is 8-bit and the notice says so (<code>sessionStorage</code>). "Reset and reload" clears both. Both paths were tested in the test browser with a dispatched <code>contextlost</code> event, not with a real loss.</p>
<h3>Things that bit</h3>
<ul><li>A status readout that sampled "the panel background" beside the Deploy button read 0.32 instead of 0.08: the sample point was inside the button's halo. It now samples the bottom corner.</li>
<li><code>getContext('2d', { toneMapping: 'extended' })</code> throws, so the page tries the dictionary form and falls back to no option.</li>
<li>The halo has to be clipped off the element with an even-odd clip, because the shadow of a filled shape is solid under the shape.</li></ul>
<ul><li>The WebGPU route gave <code>updateElementGeometry()</code> a transform scaled by the device pixel ratio. The transform is in CSS pixels (measured in C157 at a scale of 2: with the identity the Deploy button answers <code>elementFromPoint()</code> at its drawn place, with <code>scale(2)</code> it does not). The controls of that route were clicked at the wrong place on any screen with a ratio above 1. Corrected on 2026-11-21 with <code>/plan-followups/</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>Whether the WebGPU route shows values above 1.0 brighter than white on the test phone. To verify: press "Use a WebGPU canvas", pick "As stored", and look for the word BRIGHTER in the strip on the screen itself. Then move the headroom slider between 1.0 and 8.0: if the word appears and gets stronger, the range is shown. In a screenshot the word and the strip are 255 and 254.</li>
<li>The focus ring is not raised on the WebGPU route.</li>
<li>The effect of <code>dynamic-range-limit</code> on the canvas element. The page has a select for it.</li>
<li><code>(dynamic-range: high)</code> on the test phone. The page prints what the screen reports.</li>
<li>Whether an 8-bit readback (<code>getImageData()</code> with no <code>pixelFormat</code>) of a float16 canvas also loses the context on the phone, and whether the loss is a GPU process crash. Not tried.</li>
<li>Whether a new float16 canvas made right after the loss works on the phone. The first report's log (losses every 1.5 s, each after a restore) suggests a restored context draws again.</li>
<li>Speed of the repaint (about 15 a second, every frame during a deploy) and of the map view's full readback on a phone.</li></ul>
<h3>Open ideas</h3>
<ul><li>A WebGL route with an <code>RGBA16F</code> drawing buffer: the element arrives as 8 bits, and a shader raises pixels chosen by a mask and adds a real bloom. Not built.</li>
<li>Ask for a float destination in <code>texElementSubImage2D()</code> and unclamped values in <code>drawElementImageToTexture()</code>.</li></ul>
<p><a href="https://html-in-canvas.page/hdr-glow/">Open HDR interface: elements brighter than white</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Heat map over table cells</title>
<link>https://html-in-canvas.page/heat-map/</link>
<guid isPermaLink="true">https://html-in-canvas.page/heat-map/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>td drawable</category>
<category>drawElementImage</category>
<category>contenteditable</category>
<category>drawImage</category>
<description>A table of numbers whose cells are drawn one by one over a colour field that the canvas computes from them: a smooth gradient between neighbouring cells and contour lines. Type in a cell or run live data and the field follows.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/heat-map/"><img src="https://html-in-canvas.page/heat-map/social.jpg" width="1200" height="630" alt="The page &quot;Heat map over table cells&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas colour a real table from its numbers, with gradients that run between cells, while each cell stays an editable <code>&lt;td&gt;</code>?</p>
<p><strong>Short answer:</strong> Yes. A <code>&lt;td drawable&gt;</code> with no background is text on transparent pixels, so anything the canvas paints first shows under it.</p>
<p>
A table of requests per second, seven days by eight times of day, inside a canvas. Each <code>&lt;td&gt;</code> is drawn on its own with no background.
Under the cells the canvas paints a colour field computed from the numbers, with a smooth gradient from each cell to its neighbours and contour lines at 20, 40, 60 and 80.
Tap a number and type a new one, or press <b>Live data</b>. The numbers are the table's own text, and the field is recomputed from them.
</p>
<h3>How it works</h3>
<p>The table is laid out by the browser with <code>table-layout: fixed</code>, so all number cells are the same size. The table has no picture. Each cell has <code>drawable</code> and a transparent background, so its picture is its text and, when it has focus, its outline and caret.</p>
<p>The page reads the numbers from the cells' text. For each frame it fills a bitmap of 48 by 42 pixels: six samples across and down each cell. A sample's value is interpolated from the 4 by 4 cells around it with a Catmull-Rom curve, which passes through each cell's own number at the cell's centre.
The value picks a colour from a list of stops. <code>drawImage()</code> stretches the bitmap over the cell area with smoothing on. In "Cell blocks" each cell is one flat rectangle.</p>
<p>The contour lines come from the same samples. For each square of four neighbouring samples and each level, marching squares finds where the level crosses the square's edges and joins the crossings.</p>
<p>Then each cell is drawn at its layout position with <code>drawElementImage()</code>. With the checkbox on, a cell is scaled about its centre by its number, from 0.8 to 1.35 times, and its hit region is scaled with it.
A changed number moves the shown value towards the new one over a few frames, so the colour spreads. The text colour of a cell is switched between white and black from the brightness of its colour.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 a <code>&lt;td drawable&gt;</code> with no background has a picture with transparent pixels around its text. What the canvas painted before the cell shows through, so a canvas-drawn background needs no CSS on the cells.</li>
<li>The table lays the cells out. With <code>table-layout: fixed</code> the cell boxes are a regular grid, and <code>offsetLeft</code> and <code>offsetTop</code> of a cell are relative to the table.</li>
<li>Editing a cell's text (<code>contenteditable="plaintext-only"</code>) raises a <code>paint</code> event with no <code>requestPaint()</code>. The caret and the focus outline are part of the cell's picture.</li>
<li>A cell drawn scaled about its centre is hit tested at the scaled box.</li>
<li><code>drawImage()</code> of a 48 by 42 bitmap stretched to the cell area gives the smooth gradient at no measurable cost next to the 63 <code>drawElementImage()</code> calls of a frame.</li>
<li>Not verified: the on-screen number keyboard for <code>inputmode="numeric"</code> on a cell drawn in a canvas, and frame rate with Live data on a phone.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/heat-map.md">findings/heat-map.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, 412 px wide) on 2026-11-21. Not yet run on A159.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>&lt;td drawable&gt;</code> cells laid out by their table</td><td>works</td><td><code>display: table-cell</code>. With <code>table-layout: fixed</code> the cells are a regular grid. <code>offsetLeft</code> and <code>offsetTop</code> are relative to the table.</td></tr>
<tr><td>A cell with no background</td><td>text on transparent pixels</td><td>A red fill under the cell reads back as 255, 0, 0 at the cell's corner after <code>drawElementImage()</code>. The canvas can paint any background under real cells.</td></tr>
<tr><td>Editing a cell (<code>contenteditable="plaintext-only"</code>), or setting <code>textContent</code></td><td>raises a <code>paint</code> event</td><td>No <code>requestPaint()</code>. The caret and the focus outline are in the cell's picture.</td></tr>
<tr><td>A cell drawn at 1.3 times its size about its centre</td><td>hit at the larger box</td><td>62 px from the centre hits a cell whose unscaled half width is 50 px.</td></tr>
<tr><td>Smooth gradient between neighbouring cells</td><td><code>drawImage()</code> of a 48 by 42 bitmap</td><td>Six samples per cell each way, Catmull-Rom interpolation of the cell numbers, stretched over the cell area with smoothing. The curve passes through each cell's number at its centre (error 0 in the check).</td></tr>
<tr><td>Contour lines</td><td>marching squares on the same samples</td><td>One <code>Path2D</code> per frame, stroked under the cells.</td></tr>
<tr><td>63 <code>drawElementImage()</code> calls per frame (56 cells, 7 row heads) plus 9 column heads</td><td>holds still in <code>check:jank</code></td><td>Longest task 388 ms at 4x CPU slowdown during load and checks.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Text needs contrast on a field that goes from near black to near white. The page switches a class on each cell from the brightness of its colour when the numbers change. Doing it inside the <code>paint</code> handler would change the cell's picture during the paint.</li></ul>
<h3>Not verified</h3>
<ul><li>The numeric on-screen keyboard for <code>inputmode="numeric"</code> on a cell drawn in a canvas, and whether the page stays put when it opens.</li>
<li>Frame rate with "Live data" on a phone.</li></ul>
<h3>Ideas built</h3>
<ul><li>"Heat map over table cells" from <code>public/elements/ideas.js</code> (data).</li></ul>
<h3>Open ideas</h3>
<ul><li>The same field on WebGL through <code>lib/element-gl.js</code>, with the cells as textures and the colour computed in the fragment shader, for tables of thousands of cells.</li>
<li>A legend made of a real <code>&lt;meter&gt;</code> or <code>&lt;input type="range"&gt;</code> whose thumbs set the contour levels.</li></ul>
<p><a href="https://html-in-canvas.page/heat-map/">Open Heat map over table cells</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Hit region viewer</title>
<link>https://html-in-canvas.page/hit-regions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/hit-regions/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>elementFromPoint</category>
<category>updateElementGeometry</category>
<category>drawElementImage</category>
<category>hit testing</category>
<description>A canvas draws a card, a button, a link and a text field, then asks the browser which element it would hit at every 8 px and tints the answer over the picture. Ten cases show where the two differ: an element drawn twice, a clipped draw, copied pixels, an element that is no longer drawn, and the two answers that elementFromPoint() remembers after an element has moved.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/hit-regions/"><img src="https://html-in-canvas.page/hit-regions/social.jpg" width="1200" height="630" alt="The page &quot;Hit region viewer&quot;"></a></p>
<p><strong>Question:</strong> Where will the browser hit test each drawn element, and in which cases is that not where the canvas shows it?</p>
<p><strong>Short answer:</strong> In Chromium 157 the hit region is the full box of the last draw, turned and scaled with it. A clip, globalAlpha 0, an earlier draw of the same element and copied pixels don't change it. The later draw wins where two elements overlap. An element that is no longer drawn keeps its region. elementFromPoint() remembers its last two answers across a new draw until the document changes.</p>
<p>
The canvas draws four elements, then asks the browser which element it would hit at every 8 px and tints each square with that
element's colour. The outlines are where the canvas drew each element. Choose a case under the picture, and tap the picture to see
what a tap hits.
</p>
<h3>How it works</h3>
<ul>
<li>The page wraps <code>drawElementImage()</code>. At each call it reads <code>ctx.getTransform()</code> and stores the four corners the element is drawn to. Those are the outlines.</li>
<li>The hit regions aren't read from an API, because none reports them as shapes. The page calls <code>document.elementFromPoint()</code> at the centre of each 8 px square of the canvas, 6 rows per frame, and stores which child of the canvas the answer belongs to. The white line is the row being scanned. A full pass takes about 10 frames.</li>
<li>Chromium remembers the answers to the last two points it was asked, and a new draw doesn't clear them. A change to the document does. The scan asks about 2,500 other points before it returns to a square, so it never reads a remembered answer. The last case asks the same two points on every frame to show the memory. The counts are drawn in the canvas and not written into the page, because writing them would change the document.</li>
<li>Squares outside the window, or under another part of the page such as the menu bar, can't be asked. They're left without a tint.</li>
<li>A tap on the picture is reported from two sources: the <code>click</code> event's target, and <code>elementFromPoint()</code> at the same point.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>The hit region is the box of the last draw, with its transform.</strong> A turned and scaled draw gives a turned and scaled region. The scan and the recorded corners agree except in squares on the edge.</li>
<li><strong>One element has one region.</strong> Of two draws of the same element, only the second takes taps. The first is a picture.</li>
<li><strong>A clip doesn't clip the region.</strong> The card clipped to a circle is hit in the corners of its box, where nothing of it is shown. <code>updateElementGeometry()</code> has a <code>canvasClip</code> option for this (see <a href="https://html-in-canvas.page/portal/">/portal/</a>). This page doesn't use it.</li>
<li><strong><code>globalAlpha = 0</code> still places the element.</strong> The button takes taps where nothing is drawn. <a href="https://html-in-canvas.page/layout-debug/">/layout-debug/</a> uses this on purpose to measure layout.</li>
<li><strong>Copied pixels aren't hit.</strong> <code>drawImage()</code> of a part of the canvas shows the link a second time, and a tap on the copy reaches the canvas.</li>
<li><strong>Where two elements overlap, the later draw is hit.</strong> The order in the document and <code>z-index</code> don't matter.</li>
<li><strong>An element that is no longer drawn keeps its region.</strong> The link's region stays where it was last drawn, and it takes taps there.</li>
<li><strong>A remembered answer outlives a new draw.</strong> <code>elementFromPoint()</code> returns the old element at a point it was asked before the element moved. This is the Chromium bug recorded for <code>updateElementGeometry()</code> in FINDINGS.md. This page adds three measurements. It happens for plain 2D draws too. Only the last two points asked are remembered: after two other points are asked, the answer is new. <code>elementsFromPoint()</code> doesn't use the memory. A change to an attribute or to text clears it, and time alone (200 ms, several frames) does not.</li>
<li><strong>How long the memory lasts differs between pages, and the reason isn't known.</strong> In a page with one canvas and nothing else, the old answer was still returned 240 frames after the element moved. On this page, in the last case, it was returned for 14 to 20 frames after each jump (about 42 of 360 frames in 6 seconds) and then corrected itself with no change to the document that a MutationObserver could see.</li>
<li><strong>A real click wasn't affected in one test.</strong> A script moved the mouse to a remembered point, moved the element away without a document change, and pressed. The click went to the canvas, which is the new answer. This was one run in headless Chromium 157 with a mouse.</li>
<li><strong>Not verified here:</strong> a finger on a phone. Touch adjustment (the browser choosing a nearby target for a fat finger) may move a tap near an edge onto an element that <code>elementFromPoint()</code> doesn't report. Tap near the edges of the button and compare the two lines in the status text.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/hit-regions.md">findings/hit-regions.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21 by the page's live checks, by <code>node tools/devtools-pages/verify.mjs</code> (the real click) and by one-off scripts (the last three rows). The viewer asks <code>document.elementFromPoint()</code> at the centre of each 8 px square.</p>
<table><thead><tr><th>Case</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A straight 2D draw</td><td>region equals the drawn box</td><td>50 of 50 squares agree.</td></tr>
<tr><td>A draw turned 45 degrees</td><td>region turns with it</td><td>86 squares agree, 2 on the edge differ. A corner of the bounding box hits the canvas.</td></tr>
<tr><td>The same element drawn twice</td><td>only the second draw is hit</td><td>66 squares show the button and are not hit.</td></tr>
<tr><td>A draw under a clip</td><td>region is not clipped</td><td>The hidden half hits the button where the pixel has alpha 0.</td></tr>
<tr><td><code>globalAlpha = 0</code></td><td>still hit</td><td>49 squares hit and show nothing.</td></tr>
<tr><td>Two elements overlapping</td><td>the later draw is hit</td><td>Checked in both orders.</td></tr>
<tr><td>An element no longer drawn</td><td>keeps its region</td><td>Asked after a frame that drew nothing and an attribute toggle.</td></tr>
<tr><td><code>updateElementGeometry()</code> after a 2D draw</td><td>moves the region</td><td>In the visible page, under an emulated device pixel ratio of 2, the matrix had to be in canvas buffer pixels: <code>translate(x * k, y * k).scale(k)</code>. FINDINGS.md records that this differs between canvases, and the viewer shows where the region lands.</td></tr>
<tr><td><code>drawImage()</code> copy of an element's pixels</td><td>not hit</td><td>A tap on the copy reaches the canvas.</td></tr>
<tr><td><code>elementFromPoint()</code> at a point asked before a 2D redraw moved the element</td><td>returns the old element</td><td>A change to an attribute or to text clears it.</td></tr>
<tr><td>How many points are remembered</td><td>2</td><td>After two other points were asked, the first point gave the new answer.</td></tr>
<tr><td><code>elementsFromPoint()</code> at a remembered point</td><td>new answer</td><td>It does not use the memory.</td></tr>
<tr><td>A real mouse click at a remembered point</td><td>went to the new target</td><td>One run with a mouse.</td></tr>
<tr><td>How long a remembered answer lasts with no document change</td><td>240 frames and more in a page with one canvas; 14 to 20 frames on <code>/hit-regions/</code></td><td>The reason for the difference is not known. A MutationObserver on the document saw no change.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first version of the last case scanned the whole grid without changing the document and expected stale squares. There were none: with a memory of two points, a scan of 2,500 points never reads a remembered answer. The case now asks two fixed points on every frame.</li>
<li>Writing the counts into the status line on every pass changed the document and cleared the memory. The counts are drawn in the canvas.</li>
<li><code>elementFromPoint()</code> returns null outside the window and another element where the menu bar or a check fixture covers the canvas. Those squares are left without a tint.</li>
<li>The check fixtures need <code>pointer-events: auto</code> on the shared test stage, which other pages set to <code>none</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>A finger on a phone. Touch adjustment may send a tap near an edge to an element that <code>elementFromPoint()</code> does not report. Tap near the edges of the button and compare the two lines in the status text.</li>
<li>Whether a tap (not a mouse click) at a remembered point uses the memory.</li>
<li>WebGL and WebGPU canvases. The viewer's recorder wraps the 2D <code>drawElementImage()</code> only.</li></ul>
<p><a href="https://html-in-canvas.page/hit-regions/">Open Hit region viewer</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Iframes as tiles: sizing, focus, prerender and limits</title>
<link>https://html-in-canvas.page/iframe-tiles/</link>
<guid isPermaLink="true">https://html-in-canvas.page/iframe-tiles/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>iframe</category>
<category>frame-sizing</category>
<category>Permissions Policy</category>
<category>prerender</category>
<description>A board of iframe tiles in one canvas. Measures frame-sizing: content-height, a focus policy on embedded content, cross-origin iframe prerendering, and what the canvas gets from a cross-origin iframe.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/iframe-tiles/"><img src="https://html-in-canvas.page/iframe-tiles/social.jpg" width="1200" height="630" alt="The page &quot;Iframes as tiles: sizing, focus, prerender and limits&quot;"></a></p>
<p><strong>Question:</strong> Can an iframe tile in a canvas take its height from its document, be stopped from taking focus, and be drawn when it's cross-origin?</p>
<p><strong>Short answer:</strong> <code>frame-sizing: content-height</code> parses and does nothing in Chromium 157, so tiles are sized by message. A same-origin iframe is drawn. A cross-origin or sandboxed iframe is drawn as transparent pixels in 2D and WebGL, and still takes clicks.</p>
<p>
An <code>&lt;iframe&gt;</code> can be a child of a drawable canvas, and the canvas draws the whole embedded document. I had four questions about that:
can a tile take its height from the document inside it, can the embedder stop a tile from taking focus, is a cross-origin tile loaded while the page is prerendered, and what does the canvas get from a cross-origin tile.
</p>
<h3>Findings</h3>
<ul>
<li><strong><code>frame-sizing: content-height</code> doesn't size an iframe in Chromium 157 or 153.</strong> The property parses and <code>window.requestResize()</code> exists, but the call throws <code>NotAllowedError</code> ("allowed only from HTML documents with <code>responsive-embedded-sizing</code> meta tags") in a document that has the tag, and the iframe stays 150 px tall. The board sizes tiles by message. The first two measurements pass on a browser where the CSS works.</li>
<li><strong>A same-origin iframe is drawn like any element.</strong> A change inside it raises the canvas's <code>paint</code> event with no <code>requestPaint()</code>.</li>
<li><strong>A cross-origin or sandboxed iframe is drawn as nothing.</strong> <code>drawElementImage()</code> doesn't throw; every pixel is transparent. <code>texElementSubImage2D()</code> gives a WebGL shader the same empty texture. The iframe is still hit tested where it was drawn, so a click reaches a document the person can't see. A board has to draw something of its own in that place.</li>
<li><strong>To put a shader on another origin's content, that origin has to draw itself.</strong> The <a href="https://html-in-canvas.page/embed/">embeddable cards</a> page does this: the provider draws its own DOM into a canvas the host lent it.</li>
<li><strong><code>allow="focus-without-user-activation 'none'"</code> is enforced in Chromium 153 with experimental features on, and not in the 157 test build.</strong> Where it is enforced, <code>focus()</code> on load inside the tile leaves focus with the page. Without it, a tile takes focus as soon as it loads, same-origin or not.</li>
<li><strong>The prerender comparison hasn't been measured.</strong> A browser driven by automation refuses to prerender (<code>PrerenderingDisabledByDevTools</code>), so both linked pages report that they weren't prerendered. It needs a person: press the button, wait a few seconds, then open each link. Each page lists which tiles had loaded before it was shown.</li>
<li><strong>Removing an iframe during a <code>paint</code> event crashes the tab in Chromium 157.</strong> This includes a microtask of the handler. Losing a WebGL context there, while the canvas holds an iframe, crashed it too. The measurements on this page leave the event with a timer before they remove a fixture.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/iframe-tiles.md">findings/iframe-tiles.md</a> in the repository.</p>
<p>Demo 22 (<code>iframe-tiles</code>) of the Chrome APIs plan. Measured in C157 and C153 on 2026-11-21.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>frame-sizing: content-height</code> on a same-origin iframe</td><td>does nothing</td><td>The property parses. The iframe stays 150 px tall around a 512 px document.</td></tr>
<tr><td><code>window.requestResize()</code> in the embedded document</td><td>throws</td><td><code>NotAllowedError</code>, "allowed only from HTML documents with responsive-embedded-sizing meta tags", in a document that has the tag. Same in 153.</td></tr>
<tr><td>Height sent by <code>postMessage</code> from a <code>ResizeObserver</code></td><td>works</td><td>The board uses this, and records per tile which method set the height.</td></tr>
<tr><td>Same-origin iframe drawn with <code>drawElementImage()</code></td><td>works</td><td>A change inside the iframe raises the canvas's <code>paint</code> event without <code>requestPaint()</code>.</td></tr>
<tr><td>Cross-origin iframe drawn with <code>drawElementImage()</code></td><td>transparent</td><td>No exception. Every pixel reads 0,0,0,0. <code>elementFromPoint()</code> and a click at the drawn place still reach the iframe.</td></tr>
<tr><td>Sandboxed iframe (<code>sandbox="allow-scripts"</code>)</td><td>transparent</td><td>Same as cross-origin.</td></tr>
<tr><td>Cross-origin iframe with <code>texElementSubImage2D()</code></td><td>transparent</td><td>No GL error. A shader receives an empty texture.</td></tr>
<tr><td><code>allow="focus-without-user-activation 'none'"</code></td><td>153: enforced. 157 shell: not enforced</td><td>Where enforced, <code>focus()</code> on load inside the tile leaves <code>document.activeElement</code> on the page.</td></tr>
<tr><td><code>Supports-Loading-Mode: prerender-cross-origin-frames</code></td><td>not measured</td><td>The test browsers refuse to prerender under automation (<code>PrerenderingDisabledByDevTools</code>, also after <code>Page.setPrerenderingAllowed</code>). <code>/iframe-tiles/prerendered</code> and <code>/iframe-tiles/prerendered-plain</code> report which tiles loaded before activation when a person opens them.</td></tr></tbody></table>
<p>Consequences for a board:</p>
<ul><li>A cross-origin tile needs a placeholder drawn by the board, because the person can click a document they cannot see.</li>
<li>A shader on another origin's content needs that origin to draw itself, as <code>/embed/</code> does.</li></ul>
<h3>Things that bit</h3>
<ul><li>The tab crashed at the end of a measurement. The measurement resolved inside the <code>paint</code> event's microtask and the runner then removed the fixture, which holds an iframe. The runner now waits for a timer before it removes a fixture.</li>
<li><code>check:jank --checks</code> reported two focus moves. The focus measurement moves focus by design, so an automatic run skips it and it runs when the button is pressed.</li></ul>
<h3>Not verified</h3>
<ul><li><code>frame-sizing: content-height</code> and the focus policy on A159. "Run the measurements" on <code>/iframe-tiles/</code> on the phone would verify them.</li>
<li>Whether cross-origin tiles load during prerender with <code>Supports-Loading-Mode: prerender-cross-origin-frames</code>. The test browsers refuse to prerender under automation (<code>PrerenderingDisabledByDevTools</code>). A person pressing "Prerender both pages" and opening each link would verify it.</li></ul>
<p><a href="https://html-in-canvas.page/iframe-tiles/">Open Iframes as tiles: sizing, focus, prerender and limits</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>DOM elements in a Dear ImGui app</title>
<link>https://html-in-canvas.page/imgui-dom/</link>
<guid isPermaLink="true">https://html-in-canvas.page/imgui-dom/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>A Dear ImGui app compiled with Emscripten shows real &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elements with one ImGui::Image() call each. ImGui scrolls, clips and covers them.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/imgui-dom/"><img src="https://html-in-canvas.page/imgui-dom/social.jpg" width="1200" height="630" alt="The page &quot;DOM elements in a Dear ImGui app&quot;"></a></p>
<p><strong>Question:</strong> Is one ImGui::Image() call enough to put a live DOM element in a Dear ImGui window, with the browser handling its input?</p>
<p><strong>Short answer:</strong> Yes. The C++ side is about 40 lines and the browser side about 100. ImGui's own window lookup answers what is on top of an element.</p>
<p>
Dear ImGui is an immediate-mode C++ toolkit used in game engines and tools. It draws everything itself and shows whatever texture the
application gives it. This app is Dear ImGui 1.92.5 compiled with Emscripten (0.4 MB). The email, country, date and notes fields and the
line of text are real elements, each shown with one <code>ImGui::Image()</code> call on a texture filled by <code>texElementSubImage2D()</code>.
Tap a field to type. Scroll the window, drag the small window over a field, or open the ImGui combo above the fields.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Yes: one ImGui call shows a live element.</strong> <code>DomImage()</code> is about 40 lines of C++ around <code>ImGui::ImageWithBg()</code>. The browser side is about 100 lines of JavaScript inside the same file. Dear ImGui itself is unchanged. Measured in Chromium 157.</li>
<li><strong>Everything ImGui does to an image applies to the element.</strong> The window scrolls it and clips it, a second window and the combo's popup cover it, and the slider changes its tint alpha.</li>
<li><strong>ImGui can say what is on top.</strong> The browser hit tests an element wherever its geometry is. Before an event reaches an element the page calls <code>FindHoveredWindowEx()</code> (from <code>imgui_internal.h</code>) for the pointer position. If another window or a popup is on top there, ImGui gets the event and the element's hit box is moved off the canvas. The same call each frame hides an element that is under another window at the pointer.</li>
<li><strong>The window's clip rectangle maps to <code>canvasClip</code>.</strong> A field that is half scrolled out of the window takes clicks only on its visible half, and a field scrolled fully out has no hit box.</li>
<li><strong>ImGui's OpenGL backend blends straight alpha.</strong> The texture must not be premultiplied, the opposite of egui and Qt Quick on <a href="https://html-in-canvas.page/native-ui/">the earlier page</a>.</li>
<li><strong>No GLFW or SDL was needed.</strong> The WebGL2 context comes from Emscripten's <code>html5.h</code>, and the page sends pointer, wheel and key events to <code>ImGuiIO</code> through five exported functions. The whole build is 0.4 MB of WebAssembly and 93 KB of JavaScript.</li>
<li><strong>ImGui redraws only when asked.</strong> The frame function returns early unless an input event or a <code>paint</code> event asked for frames: 0 ImGui frames during 30 idle animation frames. A focused DOM field asks for frames at each caret blink.</li>
<li><strong>ImGui has no touch scrolling.</strong> The page turns a vertical touch drag into wheel input unless ImGui reports that a control or a window title is held. A press on a window body sets an active id in ImGui (the window's move id) even when windows move only by their title bar, so the test has to exclude it.</li>
<li><strong>ImGui's own text field doesn't raise a phone keyboard.</strong> <code>ImGui::InputText()</code> takes characters only from key events on the focused canvas. The DOM fields below it are the comparison.</li>
<li><strong>A press on a visible element is also sent to ImGui.</strong> An image isn't an ImGui control, so the press only focuses the window and closes an open ImGui popup. Without this an open combo stayed open while the reader typed in a DOM field.</li>
<li><strong>A lost WebGL context isn't recovered.</strong> The page shows a message and asks for a reload. The app would need to recreate ImGui's font texture and each element texture.</li>
<li><strong>Not verified on a phone.</strong> Tested in headless Chromium 157 at a 2.625 device scale with touch events: typing in a field, the slider, the combo popup over a field, and touch scrolling. Where the native select and date pickers open, and IME, need a real phone.</li>
</ul>
<p>
This page follows <a href="https://html-in-canvas.page/native-ui/">DOM elements inside egui and Qt Quick apps</a>.
Source: <a href="https://github.com/PaulKinlan/html-in-canvas-demos/tree/main/native/imgui-dom">native/imgui-dom</a>. Dear ImGui is MIT licensed.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/imgui-dom.md">findings/imgui-dom.md</a> in the repository.</p>
<p>Measured in C157 (headless, 2.625 device scale, touch) on 2026-11-21. Dear ImGui 1.92.5, Emscripten 4.0.7, WebGL2, no GLFW or SDL. Source in <code>native/imgui-dom/</code>. The build is 425 KB of WebAssembly and 93 KB of JavaScript.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A DOM element shown with one <code>ImGui::ImageWithBg()</code> call</td><td>works</td><td><code>texElementSubImage2D()</code> into a texture made with <code>glGenTextures()</code> in C++. <code>GL.textures</code> is not needed: the texture is bound by C++ before the JavaScript upload.</td></tr>
<tr><td>Hit testing where ImGui drew the element</td><td>works</td><td><code>updateElementGeometry()</code> with the item rectangle. The unit of <code>canvasTransform</code> is measured at run time.</td></tr>
<tr><td>The ImGui window's clip rectangle as <code>canvasClip</code></td><td>works</td><td>A field scrolled out of the window is not hit at its old place and is hit again after scrolling back.</td></tr>
<tr><td>Occlusion by another ImGui window or popup</td><td>works with a guard</td><td><code>ImGui::FindHoveredWindowEx()</code> answers which window is on top at a point. The page asks in a capture-phase listener and each frame.</td></tr>
<tr><td>Straight alpha texture</td><td>required</td><td>The OpenGL3 backend uses <code>glBlendFuncSeparate(SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ...)</code>, so <code>UNPACK_PREMULTIPLY_ALPHA_WEBGL</code> is false.</td></tr>
<tr><td>Tint alpha on the element</td><td>works</td><td>The fourth colour of <code>ImageWithBg()</code>.</td></tr>
<tr><td>Frames only on demand</td><td>works</td><td>0 ImGui frames during 30 idle animation frames. A paint event asks for 4 frames.</td></tr>
<tr><td>Touch: tap a field and type, drag the slider, pick from the combo popup over a field, scroll the window by dragging</td><td>works</td><td>Touch scrolling is added by the page as wheel input.</td></tr>
<tr><td><code>ImGui::InputText()</code> on a phone</td><td>not verified, expected to fail</td><td>It takes characters from key events on the canvas. Nothing in the app raises a virtual keyboard.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>emscripten_webgl_create_context("#canvas", ...)</code> did not find <code>Module.canvas</code> in a <code>MODULARIZE</code> build. The app uses the canvas id as the selector.</li>
<li>Two <code>SetNextWindowPos()</code> calls before one <code>Begin()</code>: the second replaces the first, even when its condition does not apply.</li>
<li><code>ImGui::IsAnyItemActive()</code> is true after a press on a window body, because ImGui activates the window's move id. Touch scrolling tests <code>g.MovingWindow</code> and compares the active id with <code>MoveId</code> instead.</li>
<li>An open combo popup stayed open when the reader tapped a DOM field, because ImGui never saw the press. Presses on visible elements are now forwarded as well.</li></ul>
<h3>Not verified</h3>
<ul><li>A real phone (A159): the keyboard over the canvas, where the native select and date pickers open, IME, and frame rate.</li>
<li>Screen readers. The DOM fields have roles and names; ImGui's widgets have no DOM nodes.</li>
<li>Recovery from a lost WebGL context. The page shows a message.</li>
<li>Desktop keyboard input into <code>ImGui::InputText()</code> was wired but only characters, Backspace, Delete, arrows, Home, End, Enter and Tab are sent.</li></ul>
<p><a href="https://html-in-canvas.page/imgui-dom/">Open DOM elements in a Dear ImGui app</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Five more input pickers</title>
<link>https://html-in-canvas.page/input-ideas/</link>
<guid isPermaLink="true">https://html-in-canvas.page/input-ideas/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>input type=range</category>
<category>input type=week</category>
<category>drawElementImage</category>
<category>getImageData</category>
<description>A range input drawn round a dial in slices, two date inputs on one calendar with a band between the days, a colour wheel that reads its own pixels, a year of week buttons under a fisheye, and a datalist option drawn as ghost text inside an input.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/input-ideas/"><img src="https://html-in-canvas.page/input-ideas/social.jpg" width="1200" height="630" alt="The page &quot;Five more input pickers&quot;"></a></p>
<p><strong>Question:</strong> Can one element be drawn in slices along a curve, can a canvas that draws elements read its own pixels back, and can a datalist option be drawn inside the picture of an input, with every control still a real <code>&lt;input&gt;</code>?</p>
<p><strong>Short answer:</strong> Yes to all three in Chromium 157. The hit box of a sliced element doesn't follow the curve, so the dial maps the pointer by hand.</p>
<p>
Five controls, each on a real <code>&lt;input&gt;</code> element that keeps its value, its form entry, its <code>input</code> and
<code>change</code> events and its keyboard handling, with a canvas doing the drawing. They're the ideas listed at the end of
<a href="https://html-in-canvas.page/inputs/">/inputs/</a>. Each one asks a separate question of the API: drawing one element in slices, drawing under a set of
buttons, reading pixels back from a canvas that draws elements, magnifying buttons, and drawing a datalist option inside an input.
</p>
<h3>Findings</h3>
<ul>
<li><strong>One element can be drawn many times in one frame, in pieces.</strong> <code>drawElementImage()</code> has a nine-argument form with a source rectangle, in CSS pixels of the element. The dial calls it about 134 times a frame. A clip with the five-argument form gives the same picture.</li>
<li><strong>The tick marks of a range input's datalist bend with it.</strong> They are part of the input's picture.</li>
<li><strong>The hit box doesn't bend.</strong> Each draw moves the element's one hit box, so after the slices it sits where the last slice was drawn. The dial gives the input <code>pointer-events: none</code>, maps the pointer's angle to a value itself, and finishes with one draw at no opacity that leaves the box over the whole dial.</li>
<li><strong>The focus ring isn't in the picture.</strong> An outline outside the element's border box isn't drawn by <code>drawElementImage()</code>. The dial draws its own ring, and the text input uses an outline with a negative offset.</li>
<li><strong>A canvas that draws elements can be read back.</strong> <code>drawImage()</code> from it into a second canvas works, and <code>getImageData()</code> on that copy gives the pixel. The canvas isn't tainted after <code>drawElementImage()</code> of same-origin content. The page reads through a 1 by 1 copy and never calls <code>getImageData()</code> on the drawable canvas, because on an Android phone a drawable 2D canvas made with <code>willReadFrequently: true</code> and then read lost every 2D context on the page. The colour wheel reads the pixel after drawing the wheel and before drawing the buttons, so a swatch or the marker is never read by mistake.</li>
<li><strong>A datalist option can be drawn inside the picture of an input.</strong> The source rectangle form draws the option from the end of the typed letters onwards. With the source rectangle, only the drawn part of the option is hit tested, so a tap on the ghost text reaches the option and a tap on the typed text reaches the input.</li>
<li><strong>Not verified on real hardware.</strong> These results are from Chromium 157 driven by Playwright with a mouse and emulated touch. Touch on a phone, the on-screen keyboard with the ghost text, and whether the read-only step stops the Android date and week dialogs haven't been tried.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/input-ideas.md">findings/input-ideas.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell, C157), 2026-11-21, with Playwright: mouse and keyboard at 900 px, emulated touch through CDP at 412 px, and the page's live checks. Not run on a phone.</p>
<p>The page builds five of the ideas listed at the end of <code>/inputs/</code>. Each control is a real <code>&lt;input&gt;</code> that keeps its value, form entry, <code>input</code> and <code>change</code> events and keyboard handling. The three popover pickers are built on <code>lib/placed-popover.js</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td><code>drawElementImage(el, sx, sy, sw, sh, dx, dy, dw, dh)</code>, the nine-argument form</td><td>works</td><td>The source rectangle is in CSS pixels of the element, at device pixel ratio 1 and 2. Live check: only the blue half of a red and blue button was drawn.</td></tr>
<tr><td>Hit testing after a draw with a source rectangle</td><td>only the drawn part is hit</td><td><code>elementFromPoint()</code> returned the element inside the destination rectangle and the canvas where the rest of the element would be. <code>getBoundingClientRect()</code> still reports the whole element, placed so that the source maps to the destination.</td></tr>
<tr><td>One <code>&lt;input type="range"&gt;</code> drawn about 134 times a frame in slices 3 px wide, each under its own rotation</td><td>works</td><td>The built-in track, thumb and fill follow a 240 degree arc. Half a pixel of overlap hides the joins. A clip with the five-argument form gave the same pixel counts as the source rectangle form.</td></tr>
<tr><td>Tick marks of the range input's <code>&lt;datalist&gt;</code></td><td>bend with the input</td><td>They are part of the input's picture. Live check: tick pixels inside the arc with the <code>list</code> attribute, none without.</td></tr>
<tr><td>Hit box of the sliced input</td><td>does not follow the arc</td><td>An element has one box and every draw moves it. After the slices it is the whole input turned to the angle of the last slice. Live check (expected to fail): the input was hit at the end of the arc and not at 10% or 50%.</td></tr>
<tr><td>Pointer input on the dial</td><td>mapped by hand</td><td>The input has <code>pointer-events: none</code>. The canvas turns the pointer's angle into a value, sets <code>valueAsNumber</code> (the input rounds to its step) and dispatches <code>input</code>, then <code>change</code> on release. Arrow keys, Home, End and Page Up work with no code because the input has the focus.</td></tr>
<tr><td>A last draw with <code>globalAlpha = 0</code> under a scale</td><td>sets the hit box and paints nothing</td><td>Used to leave the input's box over the whole dial, so <code>getBoundingClientRect()</code> is the dial's square (live check: 120 by 120 px for a radius of 60).</td></tr>
<tr><td>Focus ring of an input drawn by a canvas</td><td>partly missing</td><td>An outline outside the border box is not in the picture. The default ring showed as lines along the two long edges of each slice. The dial sets <code>outline: none</code> and strokes its own arc when the input matches <code>:focus-visible</code>. The text input uses an outline with <code>outline-offset: -2px</code>.</td></tr>
<tr><td>Two <code>&lt;input type="date"&gt;</code> on one <code>PlacedPopover</code> calendar</td><td>works</td><td>First press writes the start and empties the end, second press writes both in order. A press, slide and lift sets both in one touch. The band is 2D drawing in <code>under()</code>: two day numbers that move towards their targets each frame.</td></tr>
<tr><td>Finding the day under a finger during a touch drag</td><td><code>elementFromPoint()</code></td><td>Pointer events of a touch keep the element they started on as target. <code>elementFromPoint()</code> returns the day button at its drawn place.</td></tr>
<tr><td>A focused day button that slides out with its month</td><td>scrolled the page</td><td>Its hit box is moved far away, and <code>focus()</code> on a button of the incoming month then scrolled the page to the top. <code>focus({ preventScroll: true })</code> fixed it.</td></tr>
<tr><td><code>drawImage()</code> from a canvas that has had <code>drawElementImage()</code> called on it into a second canvas, then <code>getImageData()</code> on the copy</td><td>works</td><td>No exception, and <code>toDataURL()</code> works too, for same-origin content (buttons, a range input, a span). Direct <code>getImageData()</code> on the drawable canvas also worked in headless C157, but the page no longer does it: on Paul's Android phone (Chrome 159, reported 2026-11-21) a drawable 2D canvas that is read with <code>getImageData()</code> after being created with <code>willReadFrequently: true</code> loses every 2D context on the page. The wheel reads a 1 by 1 copy.</td></tr>
<tr><td>Reading the wheel's colour under the pointer</td><td>within 5 of 255 per channel</td><td>The wheel is a conic gradient for hue, a radial white gradient for saturation and a black fill for brightness. The pixel is read in <code>under()</code>, after the wheel is drawn and before the swatch buttons and the marker, so they are never read. If the read throws, the picker works the colour out from the position and records the error.</td></tr>
<tr><td>Datalist colours as buttons at the place of their own colour on the wheel</td><td>works</td><td>24 px buttons, hit tested where drawn. A drag that starts on a swatch becomes a wheel drag after 8 px.</td></tr>
<tr><td>A real <code>&lt;input type="range"&gt;</code> (brightness) drawn in a popover canvas with <code>touch-action: none</code></td><td>works by mouse and emulated touch</td><td>A touch drag from the thumb and a tap on the track both changed the value.</td></tr>
<tr><td>53 week buttons drawn at 0.57 scale with a fisheye</td><td>works</td><td>Buttons within 84 px of the focus are pushed out by <code>g(t) = (p + 1)t / (pt + 1)</code> and scaled by the mean of the radial and tangential stretch. Scaling every button up with no squeeze at the rim made the buttons overlap.</td></tr>
<tr><td>Number of ISO weeks</td><td>53 for 2026, 52 for 2027</td><td>53 when 1 January is a Thursday, or a Wednesday in a leap year. The 53rd button is not placed in a 52 week year and its hit box is moved away.</td></tr>
<tr><td>Slide and lift on the week grid</td><td>works by emulated touch</td><td>The nearest week is found from the small grid, because a radial fisheye keeps the order of distances from its centre.</td></tr>
<tr><td><code>&lt;datalist style="display:block"&gt;</code> and <code>&lt;option drawable&gt;</code> as children of the same canvas as the input</td><td>works</td><td>The canvas draws the input, then the part of one option after the typed letters, with the nine-argument form at <code>globalAlpha</code> 0.45.</td></tr>
<tr><td>Caret position from <code>measureText()</code> with the input's computed <code>font</code></td><td>matches layout</td><td>Live check: 40.20 px for "Leeds" from <code>measureText()</code> and from the option's box. The position also takes the input's border, padding and <code>scrollLeft</code>.</td></tr>
<tr><td>Tap on the ghost text</td><td>reaches the option</td><td>Because only the drawn part of the option is hit tested, a tap on the typed letters still reaches the input. <code>preventDefault()</code> on <code>mousedown</code> keeps the focus in the input.</td></tr>
<tr><td>Options written as <code>&lt;option value="Leeds"&gt;</code> with no text</td><td>draw nothing</td><td>An option renders its label. The page writes the name as the option's text.</td></tr>
<tr><td>Without HTML-in-canvas</td><td>ordinary inputs</td><td>The children of a canvas are not shown, so the dial and ghost text canvases are replaced by their inputs (<code>unwrap()</code>), and the ghost input gets its <code>list</code> attribute back. Checked by deleting <code>drawElementImage</code> before load: five notes, six visible inputs, no errors.</td></tr>
<tr><td><code>npm run check:jank -- /input-ideas/</code></td><td>passes</td><td>Checks wait for a tap. With <code>--checks</code> (checks forced to run on load) it reports layout shift 0.19 and 3 blank frames, the same kind of result as <code>/inputs/</code> (0.104 and 1).</td></tr></tbody></table>
<p>Live checks: 15, of which 14 pass and 1 fails as expected (the hit box of the sliced input), at 900 px and at 412 px with touch emulation.</p>
<h3>Things that bit</h3>
<ul><li>The first fisheye scaled buttons up near the pointer and left the rest at full base size. Buttons at the rim of the lens were pushed together and overlapped. Scaling by the local stretch of the mapping fixed it.</li>
<li>The default focus outline of the range input drew as two black lines along the arc. See the table.</li>
<li>Clicking "next month" by mouse after choosing a day scrolled the page to the top. See the table.</li>
<li>A date range fixture with a start and no end opens in the "choose the last day" state, so the first press in a check ended the range. The fixture now has both values.</li>
<li>The first emulated touch drags on the wheel began on a swatch button and did nothing, which is how the drag-from-a-swatch rule came about.</li>
<li>Playwright's <code>click()</code> on the checks button scrolls it into view. Measure page scroll after that click, not before.</li></ul>
<h3>Not verified</h3>
<ul><li>Real touch on a phone for all five demos. Open the page on Android Chrome and use each demo by finger.</li>
<li>Whether making the date and week inputs <code>readonly</code> while the replacement picker is open stops the Android date and week dialogs. Tap the fields on a phone.</li>
<li>The on-screen keyboard with the ghost text: whether the keyboard's own suggestions and composition (IME) leave the ghost text in the right place, and whether a tap on the ghost text keeps the keyboard open. Type in the Station field on a phone.</li>
<li>Screen readers. The ghost text is not announced by anything the page does, and the dial is announced as an ordinary slider. Listen with TalkBack.</li>
<li><code>getImageData()</code> after drawing an element that holds cross-origin content (for example a cross-origin <code>&lt;img&gt;</code>). A probe was written but its image from a second local port did not load in the test browser. A page with a cross-origin image inside a drawn element, read with <code>getImageData()</code>, would verify it.</li>
<li>The cost of about 134 <code>drawElementImage()</code> calls a frame on a phone GPU. (The colour wheel reads one pixel on a press and one on release, not per frame, because per-frame readback is suspected in lost contexts on the phone: <code>docs/lost-contexts.md</code>.) A frame time readout on the device would verify it.</li>
<li>The swatch buttons on the wheel are 24 px, below the usual 44 px touch target. Not tried by finger.</li>
<li>Right-to-left text and non-Latin scripts in the ghost text.</li></ul>
<h3>Open ideas, not built</h3>
<ul><li>The dial as a full turn with a wrap from maximum to minimum, for an angle or a time of day.</li>
<li>Two thumbs on one arc from two range inputs drawn into the same canvas, for a range of values.</li>
<li>The date range calendar showing two months side by side on a wide screen, with the band crossing from one to the other.</li>
<li>A lightness axis on the colour wheel drawn as a ring round it, read back the same way, in place of the slider.</li>
<li>An eyedropper mode that reads a pixel of any element drawn in the canvas, not only of the wheel.</li>
<li>The week picker with the days of the week under the pointer shown as seven small real buttons, to pick a day from the same view.</li>
<li>Ghost text that shows the second and third matches as fainter lines under the input, each a real option.</li>
<li>A file input that draws thumbnails of the chosen files, and the controls of <code>&lt;video&gt;</code> and <code>&lt;audio&gt;</code>, both still open from the list on <code>/inputs/</code>.</li></ul>
<p><a href="https://html-in-canvas.page/input-ideas/">Open Five more input pickers</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Date, time and colour pickers</title>
<link>https://html-in-canvas.page/inputs/</link>
<guid isPermaLink="true">https://html-in-canvas.page/inputs/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>input type=date</category>
<category>input type=time</category>
<category>drawElementImage</category>
<category>popover</category>
<description>A clock for &lt;input type="time"&gt;, a calendar for type="date" and swatches for type="color", each made of real buttons that a canvas moves and fades. Also every built-in form control drawn rotated in a canvas.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/inputs/"><img src="https://html-in-canvas.page/inputs/social.jpg" width="1200" height="630" alt="The page &quot;Date, time and colour pickers&quot;"></a></p>
<p><strong>Question:</strong> Date, time and colour inputs have pickers with no element to style. Can a canvas-drawn picker made of real buttons replace them on the same input, and what happens to the built-in controls when the input is drawn in a canvas?</p>
<p><strong>Short answer:</strong> The replacement pickers work with touch, mouse and keyboard. Built-in controls draw and work rotated. Their own pickers stay outside the canvas.</p>
<p>
<code>&lt;input type="date"&gt;</code>, <code>type="time"</code> and <code>type="color"</code> open pickers that the browser draws. A page can't
style them, and unlike a customisable select they have no part a canvas can go in. I tested two things. First, a replacement
picker in which every day, hour and swatch is a real button drawn by a canvas, on the same input element. Second, what happens to the
built-in controls and pickers when the input itself is drawn in a canvas.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The built-in date, time and colour pickers have no element.</strong> There is no <code>::picker()</code> for an input, <code>appearance: base-select</code> does nothing on one, and nothing can be put inside an <code>&lt;input&gt;</code>. A canvas can draw the control but not its picker.</li>
<li><strong>Built-in controls draw and work in a canvas.</strong> All thirteen kinds in the form above are drawn by one <code>drawElementImage()</code> under a rotation. Focus, typing in date segments, the range thumb and the checkbox follow the drawing with no code.</li>
<li><strong>A built-in picker opens upright at the bounding box.</strong> The colour chooser opens next to the bounding box of the rotated swatch and is not in the canvas's picture. This is the same as the <a href="https://html-in-canvas.page/select/#in-canvas">picker of a select in a canvas</a>.</li>
<li><strong>A replacement picker can be made of real buttons.</strong> In the three pickers at the top each hour, day and swatch is a <code>&lt;button&gt;</code> that is a child of a canvas in a popover. They keep focus, <code>:hover</code>, <code>:focus-visible</code>, <code>aria-pressed</code> and their accessible names while the canvas moves, scales and fades them. A button with no opacity is not drawn, and its hit box is moved away with <code>updateElementGeometry()</code>.</li>
<li><strong>The canvas draws what is not a control.</strong> The clock face, the hand and the disc under the chosen day are 2D drawing in the same canvas, under the buttons. They animate between values, which CSS on the buttons alone cannot do.</li>
<li><strong>Stopping the browser's picker.</strong> With a mouse, the date and time pickers open only from the small icon in the field, which the library hides with <code>::-webkit-calendar-picker-indicator</code>. For a touch, the library makes the input <code>readonly</code> while its own picker is open, because a read-only date or time input opens no picker. For <code>type="color"</code> it cancels the <code>click</code> event.</li>
<li><strong>Not verified on real hardware.</strong> These results are from Chromium 157 driven by Playwright with a mouse and emulated touch. That browser has no window, so the built-in date and time pickers were never seen, and whether the <code>readonly</code> step stops the Android date and time dialogs has not been tried on a phone.</li>
</ul>
<p><a href="https://html-in-canvas.page/inputs/">Open Date, time and colour pickers</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Form controls drawn as instruments</title>
<link>https://html-in-canvas.page/instruments/</link>
<guid isPermaLink="true">https://html-in-canvas.page/instruments/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawable descendants</category>
<category>drawElementImage</category>
<category>form controls</category>
<category>inert</category>
<description>A radio group as a rotary switch, a number input as an odometer, a three-step form on a turning prism, a &lt;meter&gt; bent into a dial gauge and a time input with clock hands that can be dragged. Each control keeps its value, keyboard and validation.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/instruments/"><img src="https://html-in-canvas.page/instruments/social.jpg" width="1200" height="630" alt="The page &quot;Form controls drawn as instruments&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw a form control as a different machine (a switch, a counter, a prism, a gauge, a clock) while the real control still holds the value, takes the keyboard and validates?</p>
<p><strong>Short answer:</strong> Yes for all five. A 2D canvas has no perspective and no bend, so the prism and the gauge are drawn in strips, and the page makes one flat draw to place input. An outline is outside an element's picture, so the canvas draws the focus ring of the odometer.</p>
<p>
Five ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>, built. In each one the canvas draws a form control as a different machine,
and the real control still holds the value, takes the keyboard and does its own validation. Turn the knob, type in the counter, press Next
with an empty field, and drag the clock hands. The line under each canvas is read from the form.
</p>
<h3>How it works</h3>
<p>Each canvas holds the real control as a descendant marked <code>drawable</code>. A <code>paint</code> handler draws the machine with ordinary 2D calls and draws the control, or parts of it, with <code>drawElementImage()</code>. That call also moves the control's hit region to where it was drawn, so taps, the caret and the focus order need no code. Three techniques are used more than once:</p>
<ul>
<li><b>Strips.</b> A 2D context has affine transforms only. The prism's perspective and the gauge's bend are made by drawing the same element many times, each time clipped to a narrow strip with its own transform. The last draw sets the hit region, so the prism ends each turn with one flat draw.</li>
<li><b>A grip element.</b> The knob and the clock face are canvas drawings, with no element. A round <code>drawable</code> element that is only a faint ring is drawn over each. It receives the pointer events and carries <code>touch-action: none</code>, so the rest of the canvas still scrolls the page.</li>
<li><b>The control is the state.</b> No demo keeps its own copy of the value. The paint handler reads <code>checked</code>, <code>valueAsNumber</code> or <code>value</code>, and a drag writes them.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch.</p>
<p><b>On a phone (Chrome 159 on Android, reported 2026-11-21):</b> the first version of this page lost its canvases repeatedly: a white box with a broken-picture icon, then a white screen, then an empty canvas. The cause was found later on the phone by another experiment on this site: a drawable 2D canvas created with <code>willReadFrequently: true</code>, once drawn into and read, loses every 2D context on the page about every half second. The first version's live checks made such canvases on load. This version reads pixels from a <code>drawImage()</code> copy, keeps the checks behind a tap, and after one lost context stops drawing and shows every control as plain HTML. Whether that ends the losses on the phone isn't verified.</p>
<ul>
<li><b>A radio group works with only its labels drawn.</b> The form and the fieldset aren't drawn. Each <code>drawable</code> label is drawn rotated at its own place, a tap on it checks its radio, the arrow keys move the checked radio and the focus, and <code>FormData</code> holds one value.</li>
<li><b>A <code>drawable</code> element drawn over canvas pixels works as a drag handle with its own <code>touch-action</code>.</b> A touch drag on the knob or the clock face didn't scroll the page, and a vertical swipe on the same canvas beside the knob scrolled it by the length of the swipe.</li>
<li><b>A number input with transparent text adds no pixels to the canvas.</b> It still draws its caret and its selection, and a tap between two wheels puts the caret there. So a canvas can draw the digits itself and leave editing to the input.</li>
<li><b>An outline isn't in an element's picture.</b> The picture ends at the border box. The odometer's focus ring is drawn by the canvas from <code>:focus-visible</code>, and the radio labels show focus with a border and an inset shadow.</li>
<li><b><code>stepUp()</code> raises <code>paint</code> and no <code>input</code> event.</b> The canvas redraws by itself. Code that mirrors the value somewhere else has to be told.</li>
<li><b>The browser's validation message appears at the drawn field.</b> After Next on an empty field, and after Book with the box unchecked, the message pointed at the field where the canvas had drawn it.</li>
<li><b>An <code>inert</code> fieldset is still drawn, still submitted and still validated.</b> <code>elementFromPoint()</code> returns the canvas at its place. Submitting with an invalid field on an inert face raises <code>invalid</code> on that field. The browser can't focus it, so the page turns the prism to it and focuses it.</li>
<li><b>Enter in a field on the first face submits the form</b> through the Book button on the third face, which is inert. With later fields empty, that turns the prism to the first face that has one.</li>
<li><b>Strips stand in for perspective and for a bend.</b> 28 strips for a face of the prism and 100 for the gauge leave no visible steps at these sizes. During a turn the hit region of a face is that of its last strip, so the faces are inert until the flat draw at the end.</li>
<li><b>A <code>&lt;meter&gt;</code> keeps its colour rules when bent.</b> The slices carry the green, yellow or red that the browser picks from <code>low</code>, <code>high</code> and <code>optimum</code>. Setting <code>value</code> or <code>optimum</code> raises <code>paint</code>.</li>
<li><b>Not verified:</b> everything on a phone. In particular the Android time picker that a tap on the time input may open, the on-screen keyboard over the odometer and the prism, where the validation message appears on Android, and how the strips perform on a real GPU.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/instruments.md">findings/instruments.md</a> in the repository.</p>
<p>Five ideas from the element catalogue (group 1 of the backlog in PLAN.md). Measured in headless Chromium 157 (C157) on 2026-11-21 with a mouse, a keyboard and emulated touch at 412 px wide. The page's eight live checks pass there, and <code>node tools/instruments/check.mjs</code> drives the five demos with real input (17 steps, all pass). The first version of the page lost its canvases on Chrome 159 on Android (A159, reported 2026-11-21). See "Lost canvases on the phone" below.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Rotary switch: five <code>&lt;label drawable&gt;</code> of one radio group, each drawn rotated round a knob. The form and fieldset are not drawn</td><td>works</td><td>A tap on a drawn label checks its radio. Arrow keys move the checked radio and the focus. <code>FormData</code> holds one value. The knob has no state: it reads which radio is checked.</td></tr>
<tr><td>A drag handle for a shape that is only canvas pixels (the knob, the clock face)</td><td>works</td><td>A round <code>drawable</code> element that is only a faint ring is drawn over it. It gets the pointer events. Its <code>touch-action: none</code> applies at the drawn place: a touch drag there scrolled the page by 0 px, and a swipe elsewhere on the same canvas (<code>touch-action: pan-y</code>) scrolled it by 150 px.</td></tr>
<tr><td>Odometer: <code>&lt;input type="number"&gt;</code> with transparent text over digit wheels drawn by the canvas</td><td>works</td><td>The transparent input adds no pixels (live check). It still draws its caret and selection. <code>letter-spacing</code> set to wheel width minus the digit advance puts each character over its wheel. Typing, ArrowUp and select-all work in the field.</td></tr>
<tr><td>Rolling the digits from the element's own picture</td><td>not possible</td><td>When the value changes, the picture of the old value is gone, and an <code>ElementImage</code> can only be kept for the same canvas frame. The wheels are drawn with <code>fillText()</code> in the input's font.</td></tr>
<tr><td>Focus ring on a drawn input</td><td>drawn by the canvas</td><td>An <code>outline</code> is outside the border box, and the picture ends at the border box. The odometer strokes its case from <code>input.matches(':focus-visible')</code>. The radio labels use a border and an inset shadow.</td></tr>
<tr><td><code>stepUp()</code> on a drawn number input</td><td><code>paint</code>, no <code>input</code> event</td><td>The canvas redraws by itself. The line of text under the demo has to be updated by the caller.</td></tr>
<tr><td>Prism: one form, three <code>&lt;fieldset drawable&gt;</code>, a 2D context</td><td>works</td><td>Each face is 28 vertical strips while it turns, each one clipped <code>drawElementImage()</code> with its own x and y scale. At rest the front face is one flat draw, which sets the hit region. A field is then found at its flat place to 0.0 px (live check).</td></tr>
<tr><td>Browser validation on a face of the prism</td><td>works</td><td><code>reportValidity()</code> after Next, and the submit button with a box unchecked, showed the browser's message pointing at the field where it was drawn (seen in screenshots, C157 headless). <code>:invalid</code> styles are in the picture.</td></tr>
<tr><td><code>inert</code> on the faces that are turned away</td><td>drawn, submitted, validated, not hit</td><td>An inert fieldset is drawn. <code>elementFromPoint()</code> returns the canvas at its place. Its fields are in <code>FormData</code> and still fail <code>checkValidity()</code> with an <code>invalid</code> event.</td></tr>
<tr><td>Submit while an invalid field is on an inert face</td><td>handled by the page</td><td>The browser raises <code>invalid</code> on every invalid field and cannot focus an inert one. The page cancels those events, turns to the face of the first one and focuses it after the turn.</td></tr>
<tr><td>Enter in a text field on face 1</td><td>submits</td><td>Implicit submission goes through the form's submit button, which is on the inert third face. With later fields empty the prism turns to the first of them.</td></tr>
<tr><td>Gauge: one <code>&lt;meter&gt;</code> drawn in 100 slices round a 240 degree arc</td><td>works</td><td>Each slice is a clipped draw, rotated to its angle and stretched 1.5 times along the arc. The slices carry the colour the browser picks from <code>low</code>, <code>high</code> and <code>optimum</code>: rgb 16,124,16 at the optimum, 216,59,1 two regions away (live check). Setting <code>value</code> or <code>optimum</code> raises <code>paint</code>.</td></tr>
<tr><td>Clock: <code>&lt;input type="time"&gt;</code> under a drawn face, hands dragged</td><td>works</td><td>The page reads <code>valueAsNumber</code> and writes <code>value</code> plus an <code>input</code> event during a drag. The minute hand carries into the hour past 12. Typing in the field moves the hands through every minute in between.</td></tr></tbody></table>
<h3>Lost canvases on the phone</h3>
<p>Reported from Chrome 159 on Android on 2026-11-21, on the preview of the first version: the rotary canvas as a white box with the broken-picture icon, then a white screen, then an empty canvas, repeatedly. The page has no WebGL or WebGPU context. Headless Chromium 157 with software rendering does not lose a context.</p>
<p>Cause, reported on 2026-11-21 at 19:30 UTC by the thread that tested on the phone (pull request #84, <code>public/crashes/cases.js</code>): a drawable 2D canvas created with <code>willReadFrequently: true</code>, once drawn into and read, loses every 2D context on the page about every half second. The first version's live checks made such canvases on load. The second commit of this page had already removed them. The other rows of the table below were suspects only.</p>
<p>What the first version did that the pages reported as working on the phone do not, all removed:</p>
<table><thead><tr><th>Removed</th><th>Why it was a suspect</th></tr></thead><tbody><tr><td>Live checks that ran on load</td><td>Eight fixture canvases made and removed in the first seconds, beside the demo. The guidance for new pages is to keep checks behind a tap. The page now has <code>&lt;meta name="checks" content="tap"&gt;</code>.</td></tr>
<tr><td>Fixture canvases made with <code>willReadFrequently: true</code> (the cause, see above)</td><td>That asks for a canvas kept in main memory, and <code>drawElementImage()</code> then has to bring an element picture back from the GPU. Checks now read from a small <code>drawImage()</code> copy.</td></tr>
<tr><td><code>drawElementImage()</code> with <code>globalAlpha = 0</code> of an element with no content (the drag handles)</td><td>An empty picture, drawn every frame. The handles are now a faint ring, drawn normally.</td></tr>
<tr><td>An input whose picture is completely transparent (the odometer)</td><td>The same. It has a faint bottom border now.</td></tr>
<tr><td><code>shadowBlur</code> on canvas fills</td><td>Not used by the other 2D pages. Replaced with plain fills.</td></tr>
<tr><td>Demos started 300 px before they reach the screen</td><td>Two canvases were drawing at load. The margin is 100 px.</td></tr></tbody></table>
<p>What the page now does when a context is lost: the first <code>contextlost</code> on any of the five canvases stops all five, moves their controls out into plain HTML where the canvas was, prints <code>window.__gfx.summary()</code> under them, and sets a <code>sessionStorage</code> flag so that a reload starts as plain HTML. A button clears the flag. Tested by dispatching <code>contextlost</code> on one canvas: all five show plain controls and each demo still reports its form value.</p>
<h3>Things that bit</h3>
<ul><li><code>canvas { display: block }</code> in a page's styles beats the <code>hidden</code> attribute, so a hidden canvas stayed on screen as an empty box until the rule was written for <code>:not([hidden])</code>.</li>
<li><code>click()</code> on a <code>&lt;label&gt;</code> moves focus to its radio. A live check that did that failed the jank guard (<code>focusMoves 1</code>). The check now calls <code>click()</code> on the radio found by <code>elementFromPoint()</code>.</li>
<li>One submit raises <code>invalid</code> once for every invalid field. Turning the prism on each event ended on the last invalid face. The first event in a task decides.</li>
<li>Shading each strip of a turned face separately left dark seams where strips overlap by half a pixel. The shade is now one fill over the outline of the face.</li>
<li><code>offsetLeft</code> of a field in a fieldset is measured from the fieldset's padding edge, so a check that compares drawn and layout positions has to add <code>clientLeft</code>.</li>
<li>The fixed <code>&lt;output&gt;</code> under a demo needs room for its longest text, or the page below moves when the form is submitted.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: whether this version keeps its canvases. If one is lost, the line under the plain controls says which contexts were made and lost.</li>
<li>Chrome 159 on Android: the five demos by touch. <code>node tools/instruments/check.mjs</code> covers touch only through CDP events.</li>
<li>Whether a tap on the drawn time input opens the Android time dialog, and where. Open <code>/instruments/#clock</code> and tap the field.</li>
<li>The on-screen keyboard over the odometer and the prism, and whether the canvas stays in view. Tap the wheels.</li>
<li>Where Android shows the validation message for a field on the prism. Press Next with the name empty.</li>
<li>The speed of 56 strip draws per frame (prism) and 101 draws per frame (gauge with "Wander") on a phone GPU.</li>
<li>A screen reader on any of the five.</li></ul>
<h3>Open ideas</h3>
<ul><li>Wheel taps: tap the top or bottom half of one odometer wheel to step that digit.</li>
<li>The prism on WebGL through <code>lib/element-gl.js</code> with <code>updateElementGeometry()</code> and a perspective matrix, so the faces take input during the turn.</li>
<li>A second hand on the clock from <code>step="1"</code>, and a 24 hour dial.</li></ul>
<p><a href="https://html-in-canvas.page/instruments/">Open Form controls drawn as instruments</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Keycaps drawn from kbd</title>
<link>https://html-in-canvas.page/keycaps/</link>
<guid isPermaLink="true">https://html-in-canvas.page/keycaps/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>kbd</category>
<category>drawable descendants</category>
<category>keydown</category>
<category>getLayoutMap</category>
<description>A shortcut list and a keyboard made of &lt;kbd&gt; elements. The canvas draws each one as a keycap that goes down while the real key is held, or while a finger is on it. A press sends a ring of light across the other keys.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/keycaps/"><img src="https://html-in-canvas.page/keycaps/social.jpg" width="1200" height="630" alt="The page &quot;Keycaps drawn from kbd&quot;"></a></p>
<p><strong>Question:</strong> Can each <code>&lt;kbd&gt;</code> in a document be drawn as its own moving keycap, driven by the real keyboard and by touch, while the list around it stays one drawn element?</p>
<p><strong>Short answer:</strong> Yes. A <code>&lt;kbd drawable&gt;</code> inside a drawn element is left out of the parent's picture, draws on its own and keeps its own hit region.</p>
<p>
A list of shortcuts and a small keyboard, written with <code>&lt;kbd&gt;</code> elements. The canvas draws each <code>&lt;kbd&gt;</code> as a keycap. Hold a key on a hardware keyboard and its cap goes down
until the key comes up. On a phone, press a cap with a finger, or type in the field under the canvas with the on-screen keyboard. A row of the list lights while all of its keys are down.
</p>
<h3>How it works</h3>
<p>The section is one <code>drawable</code> child of the canvas, and its picture holds every label, counter and legend. On <code>paint</code> the canvas draws the section once. Then, for each <code>&lt;kbd&gt;</code>, it draws
a dark well, the side of the cap and the face over the legend at rest, and copies the box of the <code>&lt;kbd&gt;</code> from the section's picture onto the face with the nine-argument <code>drawElementImage()</code>.
A pressed key gets its face and its legend 5 px lower. <code>offsetLeft</code> and <code>offsetTop</code> give the box of each key.</p>
<p>The first version of this page gave every <code>&lt;kbd&gt;</code> the <code>drawable</code> attribute and drew each one with its own call. That works in a small canvas, and a live check below still does it.
On this page the keys that were below the bottom edge of the window had empty pictures. The Findings section has the details.</p>
<p>A key goes down on <code>keydown</code> and comes up on <code>keyup</code>. The keys of the keyboard block are matched by <code>event.code</code>, which names the physical key. The keys in the list are matched by
<code>event.key</code>. A spring moves each cap, and each press starts a ring that travels outward and dips the keys it passes. The page asks for frames only while a cap or a ring is moving.</p>
<p>The on-screen keyboard of Chrome for Android reports most keys as <code>key: "Unidentified"</code> in <code>keydown</code>. The text field under the canvas reads the typed character from
<code>beforeinput</code> and presses the matching cap for 140 ms. The line under the field shows the last event as the browser reported it.</p>
<h3>Findings</h3>
<ul>
<li>A piece of the section's picture, drawn with the nine-argument <code>drawElementImage()</code>, moves a legend without making the <code>&lt;kbd&gt;</code> a drawable of its own. Pointer events still reach the
<code>&lt;kbd&gt;</code>: hit testing inside the drawn section finds it at its layout position.</li>
<li>A <code>&lt;kbd drawable&gt;</code> inside a <code>drawable</code> section is left out of the section's picture and draws with its own call. In Chromium 157 the picture of such a nested drawable holds only the part of it that is
inside the window. A direct child of the canvas is recorded whole, wherever it is. The last live check measures both.</li>
<li>Changing the text of a <code>&lt;kbd&gt;</code> (the layout map does this) fires <code>paint</code> with no call from the page.</li>
<li><code>navigator.keyboard.getLayoutMap()</code> returns the character on each physical key in a top-level page on desktop Chromium. The page uses it to relabel the keyboard block. Chrome for Android doesn't have it, and the block keeps its QWERTY labels.</li>
<li>A <code>keyup</code> can be lost: when the window loses focus while a key is down, and on macOS for keys released while the Command key is held. The page releases every key on <code>blur</code> and when the Meta key comes up.</li>
<li>With one drawable per key, the keys below the bottom edge of the window at load were blank on this page, and scrolling them into the window didn't paint them. <code>drawElementImage()</code> didn't throw.
A paint-affecting style change on a key while it was inside the window (<code>text-shadow: 0 0 0 transparent</code>) made the browser record it. The page no longer depends on this.</li>
<li>Not verified: Chrome 159 for Android. What the on-screen keyboard reports in <code>keydown</code> and <code>beforeinput</code>, whether a finger press holds a cap down, and whether a hardware keyboard paired with the phone gives <code>event.code</code>.
Type in the field and read the line under it.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/keycaps.md">findings/keycaps.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21, at 412 px wide with a device scale factor of 2 and at 1100 px wide, with Playwright key and mouse input. Not yet run on the test phone (Chrome 159 for Android).</p>
<p>Idea built: "Keycaps from kbd" from <code>public/elements/ideas.js</code> (rank 1, text).</p>
<h3>Two routes for drawing a key</h3>
<table><thead><tr><th>Route</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Every <code>&lt;kbd&gt;</code> has <code>drawable</code>, inside a <code>drawable</code> section, and is drawn with its own <code>drawElementImage()</code> call</td><td>measured: works in a small canvas, fails on the page</td><td>The nested kbd is left out of the section's picture (0 pixels in its box) and draws alone (183 pixels). On the page, the 12 keys that were below the bottom edge of an 860 px window at load had empty pictures. Scrolling them into the window did not paint them, and <code>drawElementImage()</code> did not throw.</td></tr>
<tr><td>The section is the only drawable. Each legend is the kbd's box copied from the section's picture with the nine-argument <code>drawElementImage()</code></td><td>measured: works, used by the page</td><td>43 keys, one section draw plus 43 piece draws per frame. A final whole draw inside an empty clip (<code>home()</code>) puts the section's hit region back. <code>updateElementGeometry()</code> alone leaves it the size of the last piece.</td></tr></tbody></table>
<h3>The picture of a nested drawable</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A line of 700 letters (about 6700 px wide) with <code>drawable</code>, nested in a drawable section. Letter 3 and letter 690 copied to the canvas</td><td>measured: letter 3 draws, letter 690 draws 0 pixels</td><td>Live check on the page, expected to fail. Same at 412 px and 1100 px window widths.</td></tr>
<tr><td>The same line as a direct child of the canvas</td><td>measured: both letters draw</td><td>A direct child is recorded whole.</td></tr>
<tr><td>Which part of a nested drawable is recorded?</td><td>measured: the part inside the window at the place the element was last drawn</td><td>On <code>/split-flap/</code> a nested drum 822 px wide had letters A to U at rest. While flaps drew its digits (which moves the element's drawn position left), the digits had pictures and the letters did not.</td></tr>
<tr><td>What makes the browser record a nested drawable again?</td><td>measured: a style change that affects its paint, made while it is inside the window</td><td><code>text-shadow: 0 0 0 transparent</code> worked. <code>outline-color</code>, <code>background-position</code>, <code>text-decoration-color</code>, <code>opacity: .999</code>, <code>will-change</code>, an attribute, the same <code>color</code>, rewriting the text node with the same text and <code>requestPaint()</code> did not.</td></tr>
<tr><td>Is it tied to the site's load hold (<code>opacity: 0</code> until the page is stable)?</td><td>measured: partly</td><td>With <code>?nohold</code>, and for a key added after load, the keys below the window had pictures. The cause is not isolated.</td></tr></tbody></table>
<h3>Input</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>keydown</code> and <code>keyup</code> drive the caps</td><td>measured: yes</td><td>A dispatched <code>keydown</code> for "k" moved the legend from 12.5 px to 17.5 px, <code>keyup</code> returned it.</td></tr>
<tr><td>Does a point on a cap hit test to its <code>&lt;kbd&gt;</code> when only the section is drawn?</td><td>measured: yes</td><td><code>elementFromPoint()</code> returns the kbd, up and held. <code>pointerdown</code> has the kbd as its target.</td></tr>
<tr><td>Does changing a legend fire <code>paint</code>?</td><td>measured: yes</td><td><code>changedElements</code> holds the section. With nested drawables it held the kbd and the section.</td></tr>
<tr><td><code>navigator.keyboard.getLayoutMap()</code></td><td>measured: resolves with 0 keys in the headless browser</td><td>Not verified on a desktop with a keyboard. Not defined on Chrome for Android (reported, not run).</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Playwright with an emulated viewport and <code>--force-device-scale-factor</code> reports <code>devicePixelRatio</code> 1 while <code>devicePixelContentBoxSize</code> is doubled. Fixtures now read the scale from <code>canvas.width / clientWidth</code> at the time of use. Runs use <code>viewport: null</code> with <code>--window-size</code>.</li>
<li>Several <code>&lt;kbd&gt;</code> elements stand for the same key (two Ctrl keys in the list and one in the block). A key is held by a set of reasons (keyboard, a pointer id, a timer), so releasing one does not release another.</li>
<li>The page calls <code>preventDefault()</code> for Space and the arrow keys only while the keyboard picture has focus, so the page still scrolls normally.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 for Android: what the on-screen keyboard reports in <code>keydown</code> (expected <code>key: "Unidentified"</code>, keyCode 229) and in <code>beforeinput</code>. The line under the text field prints both.</li>
<li>A finger held on a cap: whether <code>pointercancel</code> arrives when the page starts to scroll and releases the key.</li>
<li>A hardware keyboard paired with the phone, and <code>getLayoutMap()</code> on a desktop with a non-QWERTY layout. To verify: open the page there and read the status line.</li>
<li>Lost <code>keyup</code> on macOS while Command is held. The release-all on Meta up is written from documentation, not run.</li></ul>
<h3>Open ideas</h3>
<ul><li>Read a page's real shortcuts from <code>accesskey</code> and <code>aria-keyshortcuts</code> attributes and build the sheet from them.</li>
<li>Gamepad and MIDI keys drawn the same way.</li>
<li>Keyboard Lock (<code>navigator.keyboard.lock()</code>) in fullscreen, so that Esc and browser shortcuts reach the page.</li></ul>
<p><a href="https://html-in-canvas.page/keycaps/">Open Keycaps drawn from kbd</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Landmark map</title>
<link>https://html-in-canvas.page/landmark-map/</link>
<guid isPermaLink="true">https://html-in-canvas.page/landmark-map/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>landmarks</category>
<category>ARIA</category>
<category>aria-label</category>
<category>drawElementImage</category>
<description>A canvas draws a small page in grey and tints each landmark region with a colour for its role, labelled with the role and the name. Elements that look like landmarks and aren't get a dashed outline. A switch adds three faults, which are outlined in red.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/landmark-map/"><img src="https://html-in-canvas.page/landmark-map/social.jpg" width="1200" height="630" alt="The page &quot;Landmark map&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas show the landmark regions of the content it draws, with the roles a screen reader would announce, and point out what is wrong with them?</p>
<p><strong>Short answer:</strong> In Chromium 157 yes, from a rule table of 20 lines that gave the same roles and names as the browser's accessibility tree for all 32 elements of the drawn page, after two corrections that the comparison found. element.computedRole doesn't exist there, so the page can't ask the browser directly. A change to aria-label raises no paint event.</p>
<p>
The canvas draws a small page in grey and tints each landmark region: the parts a screen reader lists so that its user can jump
between them. Each label is the role and the name. A dashed outline marks an element that looks like a landmark and isn't one.
Tap a region to read about it. "Add three faults" changes the small page, and the map outlines the faults in red.
</p>
<h3>How it works</h3>
<ul>
<li>The roles come from a rule table in the page's script. <code>main</code>, <code>nav</code>, <code>search</code>, <code>aside</code> and <code>form</code> have a landmark role. <code>header</code> and <code>footer</code> have one only when they aren't inside an article, aside, main, nav or section. <code>section</code> has one only when it has a name. A <code>role</code> attribute with a landmark role wins.</li>
<li>The small page's own <code>&lt;header&gt;</code> and <code>&lt;footer&gt;</code> get dashed outlines. The canvas is inside this site's <code>&lt;main&gt;</code>, so they aren't a banner and a contentinfo for the browser. "Treat the drawn page as a whole document" stops the rules at the drawn element, and the two become landmarks.</li>
<li>The name is the text of the elements in <code>aria-labelledby</code>, or <code>aria-label</code>, or <code>title</code>.</li>
<li>The small page is drawn once with <code>globalAlpha = 0</code> at 0, 0 to read where each element is, then drawn scaled to fit the canvas with <code>ctx.filter = 'grayscale(1)'</code>. The tints are drawn after it under the same transform.</li>
<li>Four faults are checked: more than one main, banner or contentinfo landmark (or no main), two landmarks with the same role that have the same name or no name, a form with no name, and text that is in no landmark.</li>
<li>A tap is a <code>click</code> on the element under the finger. The page walks up from it to the nearest landmark.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: the rule table matches the browser.</strong> A script read Chromium's accessibility tree for this page through the DevTools protocol and compared the role and name of every element of the small page with the table, with and without the faults. They agreed. The script is <code>tools/devtools-pages/verify.mjs</code>.</li>
<li><strong>Found by that comparison: ancestors outside the canvas count.</strong> The first version of the table stopped at the drawn element and called the small page's header a banner. The browser calls it a section header, because the canvas is inside a <code>&lt;main&gt;</code>. A page drawn inside another page has no banner and no contentinfo of its own.</li>
<li><strong>Found by that comparison: a form with no name has the role <code>form</code> in Chromium.</strong> The HTML accessibility mapping says it should have no landmark role. The map follows the browser and reports the missing name as a fault.</li>
<li><strong>Limit: the page can't ask the browser.</strong> <code>element.computedRole</code> and <code>computedName</code> don't exist in Chromium 157 without a flag, so a page has to carry its own rules. A live check uses them when they exist.</li>
<li><strong>Found: a change to a name raises no paint event.</strong> Setting <code>aria-label</code> doesn't change the picture, so the canvas isn't told. The page watches attributes with a <code>MutationObserver</code>.</li>
<li><strong>Works: <code>ctx.filter</code> on the drawn page.</strong> The page is drawn in grey without changing its CSS, and controls in it still take taps and typing.</li>
<li><strong>Seen in the map:</strong> the header and footer of the article, and the section with no name, aren't landmarks. The search form is a search landmark because of <code>role="search"</code>. With the faults on it is a form with no name.</li>
<li><strong>Not covered:</strong> names from <code>&lt;label&gt;</code> or content, <code>aria-owns</code>, shadow trees and landmarks inside frames.</li>
<li><strong>Not verified here:</strong> a screen reader. TalkBack's landmark navigation on the phone should list the same six regions with the same names for the canvas content. That wasn't run.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/landmark-map.md">findings/landmark-map.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21. The accessibility tree was read through the DevTools protocol by <code>node tools/devtools-pages/verify.mjs</code>. The other rows are the page's live checks.</p>
<table><thead><tr><th>What</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Role and name of every element of the drawn page, rule table against the accessibility tree</td><td>agree</td><td>32 elements as loaded and 33 with the faults on, 6 landmarks each time.</td></tr>
<tr><td><code>&lt;header&gt;</code> and <code>&lt;footer&gt;</code> of a page drawn inside a canvas that is inside the site's <code>&lt;main&gt;</code></td><td>not banner and contentinfo</td><td>The tree reports <code>sectionheader</code> and <code>sectionfooter</code>. Ancestors outside the canvas count.</td></tr>
<tr><td><code>&lt;form&gt;</code> with no name</td><td>role <code>form</code></td><td>The HTML accessibility mapping gives it no landmark role. The map follows Chromium and reports the missing name.</td></tr>
<tr><td><code>&lt;section&gt;</code> with no name, <code>&lt;header&gt;</code> and <code>&lt;footer&gt;</code> inside <code>&lt;article&gt;</code></td><td>no landmark role</td><td>Dashed outline in the map.</td></tr>
<tr><td><code>element.computedRole</code>, <code>computedName</code></td><td>do not exist</td><td>Without a flag. A page must carry its own rules. A live check compares when they exist.</td></tr>
<tr><td>Names from <code>aria-labelledby</code>, <code>aria-label</code>, <code>title</code>, in that order</td><td>works</td><td>Four sections in a fixture.</td></tr>
<tr><td>Position of a tint at a draw scaled by 0.5</td><td>on the pixels</td><td>Map 50, 25, 50 by 20; red pixels the same.</td></tr>
<tr><td>Faults found</td><td>four kinds</td><td>More than one main, two navigation landmarks with no name, a form with no name, text in no landmark.</td></tr>
<tr><td>Setting <code>aria-label</code></td><td>no paint event</td><td>0 events in 300 ms. The page uses a MutationObserver.</td></tr>
<tr><td><code>ctx.filter = 'grayscale(1)'</code> on the drawn page</td><td>works</td><td>Controls in it still take taps.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first rule table stopped at the drawn element and called the small page's header a banner. The comparison with the accessibility tree showed the difference. The page now has a switch for either scope.</li>
<li>The site's own <code>main { max-width; margin: 0 auto }</code> rule applied to the <code>&lt;main&gt;</code> of the small page and made it narrower than its siblings.</li>
<li>The shared test stage has <code>aria-hidden="true"</code>. A rule that skipped everything under an <code>aria-hidden</code> ancestor found no landmarks in any fixture, so that test stops at the root.</li></ul>
<h3>Not verified</h3>
<ul><li>A screen reader. TalkBack on the phone should list six regions for the canvas content with the names in the map. Not run.</li>
<li>Names from <code>&lt;label&gt;</code> or content, <code>aria-owns</code>, shadow trees, landmarks inside frames.</li></ul>
<p><a href="https://html-in-canvas.page/landmark-map/">Open Landmark map</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Layout debugger overlay</title>
<link>https://html-in-canvas.page/layout-debug/</link>
<guid isPermaLink="true">https://html-in-canvas.page/layout-debug/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>getBoundingClientRect</category>
<category>Range</category>
<category>measureText</category>
<category>drawElementImage</category>
<description>A canvas draws an article with a table, a row of buttons and editable text, and over it the margin, padding and content box of every element and the baseline of every line. Tap a part to read its numbers. The overlay stays on the picture when the picture is turned and scaled.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/layout-debug/"><img src="https://html-in-canvas.page/layout-debug/social.jpg" width="1200" height="630" alt="The page &quot;Layout debugger overlay&quot;"></a></p>
<p><strong>Question:</strong> Can the canvas that draws an element also draw that element's boxes, margins and baselines over it, at any draw transform, without changing the element?</p>
<p><strong>Short answer:</strong> In Chromium 157 yes. Client rectangles of a drawn element are bounding boxes after a turned draw, so the page draws the element once at 0, 0 with globalAlpha 0, reads the layout there, then draws it for real. Baselines come from Range rectangles plus the font's ascent and match a probe to 0.5 px.</p>
<p>
The canvas draws an article, and over it the boxes that layout gave each element: margin in orange, padding in green, the baseline
of each line of text in pink. Tap a part of the article to see that element alone, with its size. Drag "Width" to make the article
lay out again. "Turn the picture" draws the article at an angle, and the overlay turns with it.
</p>
<h3>How it works</h3>
<ul>
<li>Each frame has three steps. The article is drawn at 0, 0 with no transform and <code>globalAlpha = 0</code>. Nothing appears, and for that moment <code>getBoundingClientRect()</code> of every descendant is its layout position plus the canvas position. The page reads all of them. Then the article is drawn where it belongs, which also puts hit testing there.</li>
<li>Margin, border and padding widths come from <code>getComputedStyle()</code>. The margin is drawn as the ring between the border box and the border box grown by the margins.</li>
<li>A baseline is found without adding anything to the document. A <code>Range</code> over a text node returns one rectangle per line. The rectangle is the inline box, as tall as the font's ascent plus descent. The ascent comes from <code>measureText().fontBoundingBoxAscent</code> for the same font.</li>
<li>The overlay is drawn in the article's own coordinates under the same canvas transform as the article, so a rotation or scale needs no extra arithmetic.</li>
<li>A tap is a <code>click</code> on the element under the finger. No coordinates are converted: the browser hit tests the drawn article.</li>
<li>The canvas redraws on the <code>paint</code> event, so typing in the last paragraph or dragging "Width" measures everything again.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: a measuring draw with no ink.</strong> A draw with <code>globalAlpha = 0</code> places the element, so layout rectangles can be read at 0, 0 and the element drawn elsewhere in the same frame. Hit testing ends at the last draw.</li>
<li><strong>Limit: no call returns layout rectangles of a turned element.</strong> After a draw turned by 0.3 rad, <code>getBoundingClientRect()</code> and <code>Range.getClientRects()</code> return bounding boxes in the canvas. <code>offsetLeft</code> and <code>offsetTop</code> give layout positions of elements as whole numbers, and nothing gives them for a line of text. <code>getBoxQuads()</code> isn't in Chromium.</li>
<li><strong>Works: baselines from the font's ascent.</strong> They match a zero-size inline-block probe to within 0.5 px for the three fonts checked. A line box that mixes sizes shares one baseline, which the pink line shows under "6" and its neighbours.</li>
<li><strong>Seen in the overlay: collapsed margins overlap.</strong> Two paragraphs with a 20 px margin each are 20 px apart, and the two orange rings lie on top of each other. Computed style reports the margin an element asked for, not the space it got.</li>
<li><strong>Seen in the overlay: a flex gap and <code>border-spacing</code> aren't margins.</strong> The space between the two buttons and between table cells has no colour.</li>
<li><strong>Not covered:</strong> baselines of form controls and images, CSS transforms on descendants, grid line names and flex free space.</li>
<li><strong>Not verified here:</strong> a phone. The overlay should be checked at a device pixel ratio of 2.625, where layout positions are fractions of a pixel, and with a system font size that isn't the default.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/layout-debug.md">findings/layout-debug.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21 by the page's live checks.</p>
<table><thead><tr><th>What</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A draw with <code>globalAlpha = 0</code> at 0, 0 used only to measure</td><td>works</td><td>It leaves no pixels and places the element, so <code>getBoundingClientRect()</code> of every descendant is its layout position for the rest of the task.</td></tr>
<tr><td>Measured box against the pixels</td><td>equal</td><td>A 60 by 40 block with a 20 px margin, root drawn at 30, 20: box at 50, 40, red pixels at 50, 40.</td></tr>
<tr><td>Hit testing after a measuring draw and a real draw</td><td>at the real draw</td><td><code>elementFromPoint()</code> found a button at 230, 140 and the canvas at 30, 20.</td></tr>
<tr><td><code>getBoundingClientRect()</code> of a descendant after a draw turned 0.3 rad</td><td>bounding box</td><td>44.1 by 30.9 for a 40 by 20 block.</td></tr>
<tr><td><code>offsetLeft</code>, <code>offsetTop</code> after the same draw</td><td>layout, whole numbers</td><td>50, 30.</td></tr>
<tr><td><code>Range.getClientRects()</code> after a turned draw</td><td>bounding boxes</td><td>No call returns the layout rectangle of a line of text once the element is drawn turned.</td></tr>
<tr><td>Baseline = top of the Range rectangle + <code>fontBoundingBoxAscent</code></td><td>matches a probe</td><td>20 px serif with line-height 2, 40 px sans-serif, 14 px monospace: difference 0.00 px against a zero-size inline-block.</td></tr>
<tr><td>Collapsed margins</td><td>overlay rings overlap</td><td>Two paragraphs with <code>margin: 20px 0</code> are 20 px apart. Computed style reports 20 px for each.</td></tr>
<tr><td>A text change with no <code>requestPaint()</code></td><td>paint event, new layout measured</td><td>1 line before, 4 lines in the next paint event.</td></tr>
<tr><td>A tap on a turned and scaled article</td><td>reaches the element under the finger</td><td>The page uses the <code>click</code> target and converts no coordinates.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first design read <code>getBoundingClientRect()</code> after the real draw and inverted the transform. That works for a translation and a scale. A rotation returns bounding boxes, which cannot be inverted. The measuring draw replaced it.</li>
<li>An <code>auto</code> margin (the chip pushed right in the flex row) is reported by computed style as the used length, so it is drawn as a margin. A flex <code>gap</code> and <code>border-spacing</code> are not margins and get no colour.</li></ul>
<h3>Not verified</h3>
<ul><li>A device pixel ratio of 2.625 on a phone, where layout positions are fractions of a device pixel, and a non-default system font size.</li>
<li>Baselines of form controls and images, CSS transforms on descendants, vertical writing modes.</li></ul>
<p><a href="https://html-in-canvas.page/layout-debug/">Open Layout debugger overlay</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Lists and tables: col, dl, ol and thead drawn by a canvas</title>
<link>https://html-in-canvas.page/list-table/</link>
<guid isPermaLink="true">https://html-in-canvas.page/list-table/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>col</category>
<category>dl</category>
<category>ol markers</category>
<category>sticky thead</category>
<category>drawElementImage source rectangle</category>
<description>Five canvases that each hold a real table or list: a light that follows the pointer along a &lt;col&gt;, a &lt;dl&gt; as cards that turn over, an &lt;ol&gt; whose items enter one after another, a sticky &lt;thead&gt; that casts a shadow, and an &lt;ol&gt; drawn along a curve with its own markers as the numbers.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/list-table/"><img src="https://html-in-canvas.page/list-table/social.jpg" width="1200" height="630" alt="The page &quot;Lists and tables: col, dl, ol and thead drawn by a canvas&quot;"></a></p>
<p><strong>Question:</strong> Which parts of a table or list can a canvas use on their own: the box of a <code>&lt;col&gt;</code>, a <code>&lt;dt&gt;</code> and its <code>&lt;dd&gt;</code>, a list marker, a sticky header inside a scroll container?</p>
<p><strong>Short answer:</strong> A <code>&lt;col&gt;</code> has a box and no picture. An outside list marker isn't in the picture of its <code>&lt;li&gt;</code>, an inside one is, and a source-rectangle draw of the <code>&lt;ol&gt;</code> has both. A <code>drawable</code> scroll container scrolls natively inside the canvas and raises <code>paint</code> on every step.</p>
<p>
Five canvases. Each holds an ordinary table or list and draws it in a way CSS does not: a light that follows the pointer along a <code>&lt;col&gt;</code>,
a <code>&lt;dl&gt;</code> as cards that turn over, an <code>&lt;ol&gt;</code> whose items enter one after another, a sticky <code>&lt;thead&gt;</code> that casts a shadow on the rows under it,
and an <code>&lt;ol&gt;</code> laid along a curve. Tap, drag and scroll inside them. The buttons, checkboxes and numbers are the real elements.
</p>
<h3>How it works</h3>
<p>Each canvas has <code>content="drawable"</code> and holds a real table or list. The parts that are drawn on their own carry the <code>drawable</code> attribute. A <code>paint</code> handler draws them with <code>drawElementImage()</code>, which also moves each element's hit box to where it was drawn. The five demos use the elements in three ways:</p>
<ul>
<li><b>An element that is read and not drawn.</b> A <code>&lt;col&gt;</code> has a box and no picture. The column light is placed from <code>col.offsetLeft</code> and <code>col.offsetWidth</code>.</li>
<li><b>An element drawn whole, at a place the canvas chooses.</b> The <code>&lt;dt&gt;</code>, <code>&lt;dd&gt;</code> and <code>&lt;li&gt;</code> elements. The glossary draws a turning card in strips, because a 2D context has affine transforms only.</li>
<li><b>A part of an element's picture.</b> <code>drawElementImage()</code> with nine arguments draws a source rectangle. The list entrance uses it to draw one row of the <code>&lt;ol&gt;</code> with its marker. The sticky header uses it to draw the top band of the scroller again with a shadow. A source-rectangle draw moves the hit box of the whole element, so both demos finish with a full draw at zero alpha to put it back.</li>
</ul>
<p>No demo runs a frame loop while it rests. A demo's script is loaded when its section comes near the screen, and it asks for frames only while something is moving.</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, at 412 px wide with a mouse, a keyboard and emulated touch.</p>
<ul>
<li><b>A <code>&lt;col&gt;</code> has a box and no picture.</b> <code>offsetLeft</code>, <code>offsetWidth</code> and <code>getBoundingClientRect()</code> return the column. <code>drawElementImage(col)</code> throws "No cached paint record for element", with or without the <code>drawable</code> attribute.</li>
<li><b>A background on a <code>&lt;col&gt;</code> is in the picture of its table.</b> Changing it raises a <code>paint</code> event.</li>
<li><b><code>&lt;dt drawable&gt;</code> and <code>&lt;dd drawable&gt;</code> in one grid cell each have a full picture.</b> The one drawn last takes the taps. A link in the <code>&lt;dd&gt;</code> is followed at the place the card was drawn.</li>
<li><b>An <code>outside</code> list marker isn't in the picture of its <code>&lt;li&gt;</code>.</b> The picture ends at the border box. A negative margin with the same padding doesn't help, because the marker is placed outside the border box. An <code>inside</code> marker is in the picture.</li>
<li><b>The picture of the <code>&lt;ol&gt;</code> has the outside markers.</b> A source-rectangle draw of one row of it gives the item with its number.</li>
<li><b>A source-rectangle draw moves the hit box of the whole element.</b> A full draw with <code>globalAlpha = 0</code> afterwards puts it back.</li>
<li><b>The <code>drawable</code> attribute can be moved between an <code>&lt;ol&gt;</code> and its items at run time.</b> The new pictures are there on the next <code>paint</code> event.</li>
<li><b><code>reversed</code> on the <code>&lt;ol&gt;</code> changes the markers in the pictures of the items</b> and raises a <code>paint</code> event.</li>
<li><b>A <code>drawable</code> scroll container scrolls natively inside a canvas</b>, by touch and by wheel, and every scroll step raises a <code>paint</code> event. <code>position: sticky</code> header cells stay at the top of its picture. A scroll container that isn't <code>drawable</code> doesn't scroll from input on its drawn descendants: the page scrolls.</li>
<li><b>A canvas shadow applies to a source-rectangle draw.</b> <code>shadowBlur</code> and <code>shadowOffsetY</code> before the nine-argument call give the header a shadow in the shape of the band.</li>
<li><b>A <code>&lt;thead drawable&gt;</code> nested in the drawable scroller also works</b> while the canvas is fully on screen. An older finding on this site says a nested drawable element is recorded only where it is inside the window when it repaints, so this page uses the source rectangle by default.</li>
<li><b>An absolutely positioned <code>&lt;li&gt;</code> keeps its list marker and its number.</b></li>
<li><b>Not verified:</b> everything on a phone. In particular the momentum of a native scroll inside the canvas, whether the page scroll takes over at the ends of the table, the frame rate of the card turn (24 draws of one element for each frame), and a horizontal touch drag on the timeline next to a vertical page scroll.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/list-table.md">findings/list-table.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, 412 px wide, mouse, keyboard and emulated touch) on 2026-11-21. Not yet run on A159. The page's 16 live checks and <code>node tools/list-table/check.mjs</code> (27 steps with real taps, touch drags and a wheel) produced the results below.</p>
<p>Backlog group 16 of PLAN.md: column highlight from <code>col</code>, glossary cards from a <code>dl</code>, staggered list entrance, sticky header that casts a shadow, timeline from an ordered list. One page with five canvases.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Does a <code>&lt;col&gt;</code> have a box inside a canvas?</td><td>works</td><td><code>offsetLeft</code> (measured from the table), <code>offsetWidth</code> and <code>getBoundingClientRect()</code> give the column. The page places the light from them.</td></tr>
<tr><td><code>drawElementImage(col)</code>, with <code>drawable</code> on the <code>&lt;col&gt;</code></td><td>fails</td><td>Throws <code>InvalidStateError: No cached paint record for element</code>. A <code>&lt;col&gt;</code> paints nothing of its own.</td></tr>
<tr><td>A background on a <code>&lt;col&gt;</code></td><td>works</td><td>It is in the picture of the table, and changing it raises a <code>paint</code> event.</td></tr>
<tr><td><code>&lt;dt drawable&gt;</code> and <code>&lt;dd drawable&gt;</code> in one grid cell of a <code>&lt;div&gt;</code> in a <code>&lt;dl&gt;</code></td><td>works</td><td>Each has a full picture of the cell's size. The one drawn last takes the taps. A link in the <code>&lt;dd&gt;</code> is followed at the drawn place.</td></tr>
<tr><td>A card turned in depth in a 2D canvas</td><td>works, in strips</td><td>24 clipped draws of the element for each frame, each with its own horizontal squeeze and vertical scale. The hit box is that of the last strip, so the page ends a turn with one flat draw.</td></tr>
<tr><td>Is an <code>outside</code> list marker in the picture of its <code>&lt;li drawable&gt;</code>?</td><td>no</td><td>The picture ends at the border box. 0% ink left of the box.</td></tr>
<tr><td><code>margin-left: -40px; padding-left: 40px</code> on the <code>&lt;li&gt;</code> to cover the marker</td><td>fails</td><td>The marker is placed outside the border box, wherever that is.</td></tr>
<tr><td><code>list-style-position: inside</code></td><td>works</td><td>The marker is in the picture, with <code>::marker</code> colour and weight.</td></tr>
<tr><td>A source-rectangle draw of one row of a drawable <code>&lt;ol&gt;</code></td><td>works</td><td><code>drawElementImage(ol, 0, li.offsetTop, ol.offsetWidth, li.offsetHeight, x, y, w, h)</code> gives the row with its outside marker.</td></tr>
<tr><td>Hit box after a source-rectangle draw</td><td>moves</td><td>The hit box of the whole element moves as if the whole element were drawn at the destination. A full draw with <code>globalAlpha = 0</code> afterwards puts it back. Agrees with <code>findings/motion.md</code>.</td></tr>
<tr><td>Move <code>drawable</code> from the items to the <code>&lt;ol&gt;</code> at run time</td><td>works</td><td>The <code>&lt;ol&gt;</code> has a picture on the next <code>paint</code> event.</td></tr>
<tr><td><code>ol.reversed = true</code></td><td>works</td><td>The markers in the pictures of the items change, and a <code>paint</code> event is raised.</td></tr>
<tr><td><code>position: absolute</code> on an <code>&lt;li&gt;</code></td><td>works</td><td>It keeps its marker and its number.</td></tr>
<tr><td>An <code>&lt;li&gt;</code> drawn rotated, with a checkbox</td><td>works</td><td><code>getBoundingClientRect()</code> of the checkbox returns the bounding box of the rotated drawing (25 px for a 20 px box at 0.3 rad), and <code>elementFromPoint()</code> there returns the checkbox.</td></tr>
<tr><td>A <code>drawable</code> scroll container (<code>overflow-y: auto</code>) inside a canvas</td><td>scrolls natively</td><td>A touch swipe of 220 px scrolled it by 205 px and the page by 0. A wheel event scrolled it. 12 <code>paint</code> events arrived during the swipe. <code>position: sticky</code> header cells stay at the top of its picture.</td></tr>
<tr><td>A scroll container that is not <code>drawable</code>, with drawable <code>thead</code> and <code>tbody</code></td><td>does not scroll</td><td>Probe script, not on the page: the same swipe and wheel scrolled the page and left <code>scrollTop</code> at 0. Agrees with <code>/minimap/</code>.</td></tr>
<tr><td><code>shadowBlur</code> and <code>shadowOffsetY</code> on a source-rectangle draw</td><td>works</td><td>The shadow has the shape of the destination rectangle. Used for the header band.</td></tr>
<tr><td><code>&lt;thead drawable&gt;</code> nested in the drawable scroller</td><td>works on screen</td><td>Has a picture after scrolling while the canvas is fully inside the window. <code>/minimap/</code> found that a nested drawable element is cut to the window when it repaints, so the page defaults to the source rectangle. The menu "Header picture" switches between the two.</td></tr>
<tr><td>A tap on a checkbox in a scrolled row</td><td>works</td><td>The row is hit at its scrolled place (tested with the source-rectangle header).</td></tr>
<tr><td>Sideways touch drag on a canvas with <code>touch-action: pan-y</code> (column light, timeline)</td><td>works</td><td>The drag reaches <code>pointermove</code>. A vertical swipe on the same canvas scrolled the page by 135 px.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>overflow: hidden</code> on an <code>&lt;li&gt;</code> removes its outside marker from the picture of the <code>&lt;ol&gt;</code> too. The first version of the "slices" route drew rows with no numbers for this reason.</li>
<li><code>'drawable'</code> on a direct child of the canvas makes it shrink-to-fit at the canvas origin (an older finding). Each table here sits in a plain <code>&lt;div&gt;</code> with <code>position: relative</code>, so <code>width: 100%</code> and <code>offsetLeft</code> work as on a page.</li>
<li>An item with an <code>IntersectionObserver</code> entrance must not be drawn before the entrance starts, or it is seen at rest and then enters.</li></ul>
<h3>Not verified</h3>
<ul><li>Everything on a phone (A159). Opening <code>/list-table/</code> and using each canvas would show it.</li>
<li>Momentum of the native scroll inside the canvas, and whether the page scroll takes over at the ends of the table.</li>
<li>Frame rate of the card turn with "Turn all": 6 cards times 24 draws for each frame.</li>
<li>A horizontal touch drag on the timeline when the finger also moves vertically.</li>
<li>Screen reader output for the <code>&lt;dl&gt;</code> cards and for the list whose items are drawn away from their layout place.</li>
<li>Dark colour scheme was not screenshotted. The colours come from the shared custom properties.</li></ul>
<h3>Ideas built</h3>
<p>From <code>public/elements/ideas.js</code> (data): "Column highlight from col", "Glossary cards from a dl", "Staggered list entrance", "Sticky header that casts a shadow", "Timeline from an ordered list". PLAN.md backlog items 16.1 to 16.5.</p>
<h3>Open ideas</h3>
<ul><li>A row light as well as a column light, from the box of the <code>&lt;tr&gt;</code>, crossing at the pointer.</li>
<li>The glossary in WebGL through <code>ElementGL</code>, where a turn is one textured quad and not 24 draws.</li>
<li>A sticky first column with a shadow to the right, using a vertical source rectangle of a scroller that scrolls both ways.</li>
<li>Markers as the only drawn part: a source rectangle of the <code>&lt;ol&gt;</code> that covers the marker column, drawn as a separate layer that moves at a different speed from the items.</li></ul>
<p><a href="https://html-in-canvas.page/list-table/">Open Lists and tables: col, dl, ol and thead drawn by a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Live captions with a second language</title>
<link>https://html-in-canvas.page/live-captions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/live-captions/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>SpeechRecognition</category>
<category>Translator</category>
<category>MediaRecorder</category>
<category>WebVTT</category>
<description>Speech becomes a caption element drawn over the video, word by word, with a translation under the frame. The words come from SpeechRecognition on the clip's own sound track or on the microphone, or from a recorded transcript. The Translator API makes the second line. Captions go into a recording of the canvas and into a WebVTT file.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/live-captions/"><img src="https://html-in-canvas.page/live-captions/social.jpg" width="1200" height="630" alt="The page &quot;Live captions with a second language&quot;"></a></p>
<p><strong>Question:</strong> Can speech recognition and the Translator API caption a video in two languages as HTML in the canvas, so the captions are in a recording of it?</p>
<p><strong>Short answer:</strong> The caption pipeline, the drawing, the recording and the WebVTT output work. Recognition and translation themselves couldn't be run in the test browser: the page reports what the device does.</p>
<p>
Speech is turned into a caption element that the canvas draws over the video, with a translation under the frame. Press Play. The page starts
with a recorded transcript of the clip, which works in every browser. Then choose speech recognition on the clip's sound or on the microphone, and
a second language.
</p>
<h3>How it works</h3>
<ul>
<li>Every source of words calls one function, <code>feed({ text, final })</code>. An interim result replaces the words on screen. A final result ends the caption and is stored with its start and end time.</li>
<li>With "speech recognition on the clip's sound", the page takes the audio track of <code>video.captureStream()</code> and passes it to <code>recognition.start(track)</code>. No microphone is opened. This needs a browser whose <code>SpeechRecognition</code> accepts a track, which the page tests for by looking for <code>processLocally</code>, added in the same release.</li>
<li>The translation comes from <code>Translator</code> when the browser has it for the language pair. A model that isn't on the device yet is downloaded after the tap on the language menu. When <code>Translator</code> can't be used, the page shows recorded translations of the clip's six sentences and says so under the player.</li>
<li>The caption element is ordinary HTML in the canvas, so the words are in <code>canvas.captureStream()</code>. Record writes the canvas and the clip's sound to a file with <code>MediaRecorder</code>.</li>
<li>The recognition events are listed under the player, because a phone has no console.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless, 2026-11-21. The rows above and the two status blocks under the player say what your browser does.</p>
<ul>
<li><strong>Works: captions as elements in the picture.</strong> Words fed in as interim and final results are drawn over the frame, and the translation under it. Both are in a <code>MediaRecorder</code> file of the canvas.</li>
<li><strong>Found: an element drawn twice has one hit-test box, at its last draw.</strong> The caption element's box under the bar reached up over the Play button, and taps on the button went to the caption (reported from a phone, 2026-11-21). The bar is now drawn after the captions, because the element drawn last is on top for taps.</li>
<li><strong>Works: only revised words change.</strong> When an interim result differs from the last one, the words that stayed the same keep their elements, so only new and revised words animate.</li>
<li><strong>Works: WebVTT from results.</strong> The file made from the final results loads back into a <code>&lt;track&gt;</code> with the same number of cues.</li>
<li><strong>Not run here: recognition.</strong> Headless Chromium 157 has <code>SpeechRecognition</code> with <code>processLocally</code>, <code>phrases</code>, <code>available()</code> and <code>install()</code>, but no recognition service. The eighth check records what <code>start(track)</code> did.</li>
<li><strong>Not run here: translation.</strong> <code>Translator.availability()</code> didn't settle in headless Chromium 157 and no model can be downloaded in the test container. The page falls back to the recorded translations there.</li>
<li><strong>Not verified:</strong> whether Chrome 159 on Android accepts <code>start(track)</code> with a track from <code>video.captureStream()</code>, whether it needs <code>processLocally</code> for that, how late interim results are against the sound, and the speed of <code>Translator</code> on a phone. The line under the player shows the time of the last translation.</li>
<li><strong>The recorded Spanish, French, German and Japanese were written by a language model</strong> for this page and haven't been checked by a speaker.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/live-captions.md">findings/live-captions.md</a> in the repository.</p>
<p>Chromium 157 headless (C157), 2026-11-21. The test browser has no speech recognition service and no translation model, so the two APIs in the title were not run end to end. The table says which rows were measured.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Interim and final results as a caption element drawn over the frame, translation under it</td><td>measured, works</td><td>Results go through one <code>feed({ text, final })</code> function. The caption element holds two paragraphs and is drawn twice with a clip, so the first is over the frame and the second under the bar.</td></tr>
<tr><td>Only revised words change</td><td>measured, works</td><td>"the page reeds" then "the page reads the": two <code>&lt;span&gt;</code> elements kept, the third replaced and marked, a fourth added. Kept words do not run their CSS animation again.</td></tr>
<tr><td>Recorded transcript fed in step with the video</td><td>measured, works</td><td><code>replayCues()</code> reads the time stamps of <code>talk.vtt</code> and feeds each word as an interim result at its time and the sentence as a final result. 9 interim results, then the final one.</td></tr>
<tr><td>WebVTT from final results</td><td>measured, works</td><td><code>toVtt()</code> output loaded through a blob URL into a <code>&lt;track&gt;</code>: 2 cues read back with their times. A literal <code>--&gt;</code> in a caption has to be replaced, or the cue fails to parse.</td></tr>
<tr><td>Captions in a <code>MediaRecorder</code> file of the canvas</td><td>measured, works</td><td>320×260 VP9 with Opus. 981 caption pixels in the bottom of the recorded frame.</td></tr>
<tr><td><code>SpeechRecognition</code> surface</td><td>measured</td><td><code>continuous</code>, <code>interimResults</code>, <code>processLocally</code>, <code>phrases</code>, <code>available()</code>, <code>install()</code> are all present in C157.</td></tr>
<tr><td><code>recognition.start(track)</code> with the audio track of <code>video.captureStream()</code></td><td>measured: starts</td><td>Events <code>start</code> and <code>audiostart</code> arrived and no error. No result followed, as there is no recognition service in the test browser.</td></tr>
<tr><td>Recognition results from the clip's sound or the microphone</td><td>not verified</td><td>Needs a device with a recognition service. The page lists every recognition event under the player.</td></tr>
<tr><td><code>Translator.availability()</code></td><td>measured: never settles in C157 headless</td><td>The page waits 3 s, then uses recorded translations of the clip's six sentences and says so.</td></tr>
<tr><td><code>Translator.create()</code> and <code>translate()</code> on interim and final text</td><td>not verified</td><td>Written to translate one request at a time, keep every final caption and drop interim requests that were overtaken. The time of the last call is shown under the player.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Reported from the phone (2026-11-21): the Play button did nothing. The caption element is drawn twice with a clip, and its hit-test box is its whole box at the last draw, which reached over the control bar. Taps on Play went to the caption paragraph. The bar is now drawn after the captions, and a live check asks <code>elementFromPoint()</code> at the button. The other four pages' Play buttons were tapped with touch input in the test browser and worked.</li></ul>
<ul><li>A new caption that replaced the last one word by word marked every word as revised. A new utterance now clears the words first.</li>
<li><code>SpeechRecognition.prototype.start.length</code> is 0 in C157 although <code>start(track)</code> is accepted, so the page cannot test for the argument. It looks for <code>processLocally</code>, which shipped with it. That is an inference.</li>
<li><code>SpeechRecognition.available()</code> crashed the tab in headless C157 on <code>/voice/</code>, so this page never calls it.</li>
<li><code>box-sizing: border-box</code> from the site's style sheet makes <code>min-height</code> include the padding. A check that assumed a 46 px caption band counted pixels of the frame.</li></ul>
<h3>Not verified</h3>
<ul><li>Whether Chrome 159 on Android accepts <code>start(track)</code> with a track from <code>video.captureStream()</code>, and whether it needs <code>processLocally</code> for that. Choose "speech recognition on the clip's sound" and read the event list.</li>
<li>How late interim results are against the sound.</li>
<li><code>Translator</code> on a phone: availability, download after the tap on the language menu, and the time per call.</li>
<li>The recorded Spanish, French, German and Japanese were written by a language model and have not been checked by a speaker.</li></ul>
<h3>Open ideas</h3>
<ul><li><code>SpeechRecognitionPhrase</code> biasing from the words on the page.</li>
<li>Speaker colours from two tracks (microphone and clip) recognised at once.</li>
<li>The translation as a second audio track through <code>SpeechSynthesis</code>, with <code>/speak-words/</code> highlighting.</li></ul>
<p><a href="https://html-in-canvas.page/live-captions/">Open Live captions with a second language</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Marker-pen highlight on mark</title>
<link>https://html-in-canvas.page/mark-pen/</link>
<guid isPermaLink="true">https://html-in-canvas.page/mark-pen/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>mark</category>
<category>getClientRects</category>
<category>drawElementImage</category>
<category>paint</category>
<description>The flat background of &lt;mark&gt; is off. The canvas draws a pen stroke along each line box of each mark, under the text: highlighter, underline, circle, box or strike. Select words to add a mark, or edit the text and the strokes follow.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/mark-pen/"><img src="https://html-in-canvas.page/mark-pen/social.jpg" width="1200" height="630" alt="The page &quot;Marker-pen highlight on mark&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas replace the background of <code>&lt;mark&gt;</code> with a drawn stroke that follows the mark's line boxes through edits and reflow, while the text stays selectable?</p>
<p><strong>Short answer:</strong> Yes. <code>mark.getClientRects()</code> gives one box per line, reported at the drawn position and scale. Edits and new marks fire <code>paint</code> on their own.</p>
<p>
The text below is one element drawn by a canvas. Its <code>&lt;mark&gt;</code> elements have no background. The canvas draws a pen stroke for each line that a mark covers, from the boxes
that <code>getClientRects()</code> returns, and draws the text over it. Select some words and press Highlight selection to wrap them in a new <code>&lt;mark&gt;</code>. Tap a mark to redraw it with the chosen pen.
Switch on editing and type: the strokes follow the new line breaks.
</p>
<h3>How it works</h3>
<p>The article is a child of a <code>&lt;canvas content="drawable"&gt;</code>. On every <code>paint</code> event the page asks each <code>&lt;mark&gt;</code> for its client rects. An inline element that wraps
returns one rect for each line, so a mark over three lines gives three boxes. The page turns each box into strokes for the mark's pen (<code>data-pen</code>), in the colour of its <code>--ink</code> custom property,
and draws them on the canvas. Highlighter and underline strokes are drawn before the article, so the glyphs are on top of the ink. Circle, box and strike strokes are drawn after it.</p>
<p>A stroke is a polyline with small random offsets. The random numbers come from a generator seeded per mark, so the stroke has the same shape on every frame and after an edit. A new mark is drawn in over time:
the page draws only the first part of each polyline and asks for another frame until the stroke is complete. When nothing is animating the page requests no frames. Typing, selecting and resizing fire <code>paint</code> themselves.</p>
<p>The text stays a normal element. It can be selected, copied, edited and found. Highlight selection changes the document: it wraps the selected range in a <code>&lt;mark&gt;</code>, which a screen reader
and a copy to the clipboard both see.</p>
<h3>Findings</h3>
<ul>
<li><code>mark.getClientRects()</code> on a mark inside a drawn element returns one rect per line, as it does outside a canvas. The rects are reported where the element was last drawn and at the scale it was drawn with.
Measured against the element's own <code>getBoundingClientRect()</code> and divided by the drawn scale, they give layout positions that can be used in the canvas's coordinate system.</li>
<li>Wrapping a range in a new <code>&lt;mark&gt;</code>, removing a mark and typing in the article each fire <code>paint</code> with no call from the page.</li>
<li>With <code>background: none</code> the mark paints nothing of its own, so the canvas can put ink under the glyphs by drawing the ink first and the element second. The selection highlight is part of the element's picture, so it's drawn over the ink.</li>
<li>A <code>Range</code> returns the same boxes as a <code>&lt;mark&gt;</code> around the same text. A canvas could draw pen strokes for ranges without changing the document. This page changes the document so that the highlight is in the markup.</li>
<li>Not verified: long-press selection and its handles on Chrome 159 for Android, and the on-screen keyboard while editing. Open the page on the phone, select two words, press Highlight selection, then switch on editing and type.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/mark-pen.md">findings/mark-pen.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21, at 412 px wide with a device scale factor of 2 and at 1100 px wide. Not yet run on the test phone (Chrome 159 for Android).</p>
<p>Idea built: "Marker-pen highlight" from <code>public/elements/ideas.js</code> (rank 1, text).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Does <code>mark.getClientRects()</code> give line boxes for a mark inside a drawn element?</td><td>measured: yes, one rect per line</td><td>A mark over three lines of a 150 px paragraph returned 3 rects on 3 lines.</td></tr>
<tr><td>Where are those rects reported?</td><td>measured: at the place and scale of the element's last <code>drawElementImage()</code> call</td><td>Drawn at twice its size, a rect 80.9 px wide became 161.8 px. <code>lineBoxes()</code> in <code>lib/text-canvas.js</code> measures against the element's own <code>getBoundingClientRect()</code> and divides by <code>rect.width / offsetWidth</code>, which gives layout positions again (40.7, 80.9 before and after).</td></tr>
<tr><td>Does a mark with <code>background: none</code> paint anything of its own?</td><td>measured: no</td><td>0 yellow pixels in the mark's box when the element is drawn alone. Ink drawn first and the element second gives ink under the glyphs.</td></tr>
<tr><td>Do edits fire <code>paint</code> without <code>requestPaint()</code>?</td><td>measured: yes</td><td>1 paint event after changing a text node before the mark, 1 after wrapping a range in a new <code>&lt;mark&gt;</code>. The mark's box moved from x 40.7 to 81.6.</td></tr>
<tr><td>Does a <code>Range</code> give the same boxes as a <code>&lt;mark&gt;</code> around the same text?</td><td>measured: yes</td><td>3 boxes each, same places. Strokes could be drawn for ranges with no change to the document.</td></tr>
<tr><td>Does a point on a drawn mark hit test to the mark?</td><td>measured: yes</td><td><code>elementFromPoint()</code> in the middle of the first box, with the paragraph drawn at 30, 20.</td></tr>
<tr><td>Cost of a paint with 7 marks and 22 strokes</td><td>measured: 0.3 ms</td><td>Software rendering. The page requests frames only while a stroke is being drawn in.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>An inline rect is as tall as the font's content area, not the line height, so the highlighter band is placed inside the rect and not scaled to the line.</li>
<li><code>Range.surroundContents()</code> throws when the selection cuts through an element (for example half of an existing mark). The page then moves the contents with <code>extractContents()</code> and <code>insertNode()</code>, and unwraps marks that ended up inside the new one.</li>
<li>On a phone a tap on a button can clear the selection before <code>click</code> runs. The page keeps the last non-empty range from <code>selectionchange</code>.</li>
<li>Strokes come from a random generator seeded per mark, so a stroke keeps its shape across frames and edits.</li></ul>
<h3>Changes after a crash report from the phone</h3>
<p>Paul reported a crashed canvas on Chrome 159 for Android on 2026-11-21 (page not named). The cause is not known and cannot be reproduced in the test browser. All five text pages were changed together:</p>
<ul><li>Live checks wait for a tap (<code>&lt;meta name="checks" content="tap"&gt;</code>).</li>
<li>Check fixtures no longer ask for <code>willReadFrequently</code> on a drawable canvas. Pixels are read from a <code>drawImage()</code> copy.</li>
<li><code>home()</code> first set the hit region with <code>updateElementGeometry()</code> in place of a draw at alpha 0. That left the region the size of the last piece (2 of 36 points hit, Chromium 157 headless, 2026-11-21; found by <code>/text-notes/</code>). It now draws the whole element inside an empty clip: 36 of 36 points hit, no pixels drawn. A draw that cannot be seen did not lose a canvas on the phone (<code>findings/canvas-loss.md</code>, trial <code>alpha0</code>).</li>
<li>No <code>shadowBlur</code> anywhere in the five pages.</li>
<li><code>/flip-clock/</code> and <code>/split-flap/</code> close each <code>ElementImage</code> snapshot before taking the next.</li>
<li>On the first trusted <code>contextlost</code> event, <code>mount()</code> stops drawing and shows the content as plain HTML with a note.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 for Android: long-press selection inside the drawn article, the selection handles, and Highlight selection after a tap on the button. To verify: select two words, press the button.</li>
<li>Editing with the on-screen keyboard (the "Edit the text" switch). To verify: switch it on, type before a mark and watch the stroke move.</li>
<li>Whether the selection menu of Android covers the canvas controls. Not measurable in the test browser.</li></ul>
<h3>Open ideas</h3>
<ul><li>Draw strokes for <code>::highlight()</code> ranges and for find-in-page matches, with no <code>&lt;mark&gt;</code> in the document.</li>
<li>Pressure and tilt from a stylus (<code>pointerrawupdate</code>) to draw the mark by hand and then snap it to the line boxes.</li>
<li>An eraser: drag over a mark to remove the element as the stroke is rubbed out.</li></ul>
<p><a href="https://html-in-canvas.page/mark-pen/">Open Marker-pen highlight on mark</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Media controls and element state</title>
<link>https://html-in-canvas.page/media-state/</link>
<guid isPermaLink="true">https://html-in-canvas.page/media-state/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>:state()</category>
<category>:has()</category>
<category>::part()</category>
<category>Presentation API</category>
<description>A mock of customisable media controls whose parts a canvas draws one by one, a card whose :checked, :open, :user-invalid and :popover-open states drive an effect through :has(), a quotation mark drawn apart from its quote, and the composed canvas sent to another screen.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/media-state/"><img src="https://html-in-canvas.page/media-state/social.jpg" width="1200" height="630" alt="The page &quot;Media controls and element state&quot;"></a></p>
<p><strong>Question:</strong> If media controls were ordinary elements with parts and states, what could a canvas do with them? Can element state drive an effect through CSS alone, does <code>drawElementImage()</code> take a pseudo-element or a part, and can the composed canvas be cast?</p>
<p><strong>Short answer:</strong> In Chromium 157 a part of an open shadow tree is drawn as its own picture, and takes input where it is drawn, once the component puts <code>drawable</code> on it. A pseudo-element is refused with a TypeError. Custom states and all four state pseudo-classes set numbers on the canvas through <code>:has()</code>. The canvas stream reached a receiver page in a second tab over WebRTC. No cast device or second screen was available, so Remote Playback and Presentation aren't verified.</p>
<p>
Four ideas that came out of <a href="https://html-in-canvas.page/player-parts/">the parts of the native media player</a>. That page found that a canvas can restyle the
native controls and can't reach any one of them. I wanted to know what a canvas could do if media controls were ordinary elements with
named parts and states, whether the state of any element can drive an effect through CSS alone, whether
<code>drawElementImage()</code> takes a pseudo-element or a part, and whether the composed picture can be sent to another screen.
</p>
<h3>How it works</h3>
<ul>
<li><b>Custom states are selectors.</b> <code>&lt;media-bar&gt;</code> adds and removes names in <code>ElementInternals.states</code> from the video's events. A rule on the canvas, <code>:has(media-bar:state(playing))</code>, sets <code>--fx-amount</code>, and a transition on the canvas eases it.</li>
<li><b>The canvas reads the numbers.</b> A change of a custom property raises no <code>paint</code> event. The canvas listens for <code>transitionrun</code> and <code>transitionend</code> on itself and asks for a frame at a time between them. When no transition runs, nothing runs.</li>
<li><b>Parts as pictures.</b> <code>drawElementImage()</code> takes any element that has the <code>drawable</code> attribute and is a descendant of the canvas, and an element in an open shadow tree of a canvas child counts. The component sets the attribute on its parts when it has the <code>lift</code> attribute.</li>
<li><b>Pseudo-elements.</b> There is no call that takes one, so the mark is drawn by clipping a draw of its whole element to the mark's box.</li>
<li><b>Casting.</b> <code>canvas.captureStream()</code> gives a video track of the drawn canvas. The sender adds it to an <code>RTCPeerConnection</code> and exchanges one offer and one answer with the receiver.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.</p>
<ul>
<li><b>Media controls built as a custom element can be drawn part by part.</b> An element in an open shadow tree of a canvas child is drawn as its own picture by <code>drawElementImage()</code> when it has the <code>drawable</code> attribute. The play button was drawn at 2.2 times its size and the timeline stretched to 335 px, and a touch on each reached the part where it was drawn: the play part's hit region was more than 55 px tall, and a tap at three quarters of the stretched timeline moved the film to 7.7 s of 10.</li>
<li><b>A part without <code>drawable</code> can't be drawn.</b> The call threw <code>InvalidStateError</code>: descendants passed to <code>drawElementImage()</code> must have the attribute. Only the component's author can add it, so this doesn't help with the native controls or with a closed tree.</li>
<li><b><code>drawElementImage()</code> doesn't take a pseudo-element.</b> <code>Element.pseudo('::before')</code> returns a <code>CSSPseudoElement</code> in this browser, and passing it threw <code>TypeError</code>. So did a <code>ShadowRoot</code>. The quotation mark is drawn apart by clipping a draw of the whole quote to a box whose place the style sheet fixes. A pseudo-element with no fixed box couldn't be found this way.</li>
<li><b>Custom states work as inputs to an effect.</b> <code>canvas:has(media-bar:state(playing))</code> set <code>--fx-amount</code> to 1 while the fixture video played and back to 0 after pause, with no listener outside the component.</li>
<li><b><code>:checked</code>, <code>details:open</code>, <code>:user-invalid</code> and <code>:popover-open</code> each drove a number through <code>:has()</code>.</b> The first three belong to elements drawn in the canvas. The popover is a sibling of the canvas, and its rule is written on their common ancestor. <code>:user-invalid</code> matched after text that isn't an address was typed and the field was left, and after Save was pressed with the field empty.</li>
<li><b>A transition of a registered custom property raises no <code>paint</code>.</b> It raised one <code>transitionrun</code> and one <code>transitionend</code> on the canvas and 0 paint events in 0.5 s, with the number at 0.44 after 150 ms of 300. The canvas asks for frames between the two events and for none afterwards.</li>
<li><b>The composed canvas can be sent as a stream.</b> <code>captureStream()</code> on the drawable canvas gave one video track, and the film with its controls arrived in the receiver page in a second tab at 378 by 288 over WebRTC, with a BroadcastChannel carrying the offer and the answer. The controls in the stream are pixels.</li>
<li><b>No cast device was available to the test browser.</b> Remote Playback reported that no device is available for a video that shows the canvas stream, and <code>prompt()</code> was rejected with <code>NotAllowedError</code>. <code>PresentationRequest.getAvailability()</code> gave false and <code>start()</code> was rejected with <code>NotFoundError</code>: no screens found. The Presentation route of the receiver page hasn't run.</li>
<li><b>Not verified:</b> everything on a phone, and both cast routes on a network with a Chromecast or a second screen. Whether Remote Playback offers a device at all for a video whose source is a <code>MediaStream</code> isn't known. In one run the frame in the receiver tab showed the glass boxes without the play, time and timeline parts while the sending tab was in the background. In a single tab the stream matched the canvas.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/media-state.md">findings/media-state.md</a> in the repository.</p>
<p>Backlog group 23 in PLAN.md, ideas 23.1 to 23.4. Measured in headless Chromium 157 (C157) on 2026-11-21 at 412 px wide. The page's eight live checks pass there, and <code>node tools/media-state/check.mjs</code> drives the demos by touch and opens the receiver in a second tab (21 steps, all pass). Nothing here has been run on a phone, and no cast device or second screen was available.</p>
<p>The questions: if media controls were ordinary elements with parts and states, what could a canvas do with them (23.1)? Can element state drive an effect through CSS alone (23.2)? Does <code>drawElementImage()</code> take a pseudo-element or a <code>::part()</code> (23.3)? Can the composed canvas be cast (23.4)?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>&lt;media-bar&gt;</code>, a custom element with four parts in an open shadow tree, as a <code>drawable</code> canvas child</td><td>drawn as one picture, controls work by touch</td><td>The mock of customisable media controls. <code>public/media-state/media-bar.js</code>.</td></tr>
<tr><td>A part of that shadow tree with the <code>drawable</code> attribute, passed to <code>drawElementImage()</code></td><td>drawn as its own picture, pixels only at its place</td><td>A descendant in an open shadow tree counts as a descendant of the canvas.</td></tr>
<tr><td>The play part drawn at 2.2 times its size, the timeline stretched to the canvas width</td><td>hit region of the play part more than 55 px tall, of the timeline 335 px wide</td><td>Input follows each part's own draw. A tap at three quarters of the stretched timeline moved the film to 7.7 s of 10.</td></tr>
<tr><td>A part without <code>drawable</code></td><td><code>InvalidStateError</code></td><td>"Descendants passed to DrawElementImage must have the 'drawable' attribute." Only the component can add it.</td></tr>
<tr><td><code>drawElementImage(element.pseudo('::before'), …)</code></td><td><code>TypeError</code></td><td><code>Element.pseudo()</code> exists and returns a <code>CSSPseudoElement</code>. The method takes <code>(Element or ElementImage)</code> only.</td></tr>
<tr><td><code>drawElementImage(shadowRoot, …)</code></td><td><code>TypeError</code></td><td></td></tr>
<tr><td>The pseudo-element drawn apart anyway</td><td>two clipped draws of the whole element</td><td>Works only for a pseudo-element whose box the style sheet fixes. The link in the quote still answers at its drawn place.</td></tr>
<tr><td><code>canvas:has(media-bar:state(playing)) { --fx-amount: 1 }</code></td><td>0 before, 1 while playing, 0 after pause</td><td>Custom states from <code>ElementInternals.states</code> are selectors like any other.</td></tr>
<tr><td>A change of custom state and <code>paint</code></td><td>3 of 14 paint events in 0.4 s of play named the bar</td><td>The state change raises <code>paint</code> because the play button's label and the time change. A state that changed no pixel would not.</td></tr>
<tr><td><code>:has(:checked)</code>, <code>:has(details:open)</code>, <code>:has(:popover-open)</code></td><td>each number 0, then 1</td><td>The popover is a sibling of the canvas. The rule is on their common ancestor.</td></tr>
<tr><td><code>:has(:user-invalid)</code> (tool script, typed text and blur)</td><td><code>--fx-x</code> between 0 and 1 after 0.25 s, 1.00 after the transition</td><td>Also matches after Save is pressed with the required field empty.</td></tr>
<tr><td>A 0.3 s transition of a registered custom property on the canvas</td><td>1 <code>transitionrun</code>, 1 <code>transitionend</code>, value 0.44 at 150 ms, 0 paint events</td><td>The canvas asks for frames between the two events. After them the status line did not change for 0.8 s.</td></tr>
<tr><td><code>canvas.captureStream()</code> on a drawable canvas, to a second <code>RTCPeerConnection</code> in the page</td><td>200 by 80 video after 106 ms</td><td>The cast path without a second screen.</td></tr>
<tr><td>The stream of the first demo to <code>receiver.html</code> in a second tab, signalling over a BroadcastChannel</td><td>378 by 288 video in the receiver</td><td>The same receiver code that a Presentation screen would run.</td></tr>
<tr><td>Remote Playback for a <code>&lt;video&gt;</code> that shows the canvas stream</td><td>"not available", <code>prompt()</code> rejected with <code>NotAllowedError</code></td><td>No device in the test browser.</td></tr>
<tr><td><code>PresentationRequest</code> for the receiver page</td><td><code>getAvailability()</code> false, <code>start()</code> rejected with <code>NotFoundError: No screens found</code></td><td>No screen in the test browser.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the three canvases and shows the video, the bar, the form and the quote as plain HTML (3 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The sender waited for <code>iceGatheringState</code> to be <code>complete</code> before it sent its offer, and in the tool script that never came within 10 s while the receiver tab was in front. The wait is now 2 s at most.</li>
<li>In one tool run the screenshot of the receiver tab showed the glass boxes without the play, time and timeline parts. Taking the screenshot puts the sending tab in the background. In a single tab the stream had the same number of orange pixels as the canvas, as one picture and as four, with the canvas on screen and off, and after a pause and play off screen.</li>
<li>The form's grid children needed <code>min-width: 0</code>, or the email field was drawn past the edge of the card.</li>
<li>The status line of the bar ended a number with a full stop, and the tool's pattern <code>[\d.]+</code> took the stop as part of the number.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the four demos by touch.</li>
<li>Remote Playback and Presentation on a network with a Chromecast or a second screen. Whether Remote Playback offers any device for a video whose source is a <code>MediaStream</code>.</li>
<li>The Presentation branch of <code>receiver.html</code> (<code>navigator.presentation.receiver</code>). Only the tab branch has run.</li>
<li>The cast between two devices. The offer carries host candidates only and there is no TURN server, so it is expected to work on one network and not across two.</li>
<li>Why the receiver's frame missed three parts while the sending tab was in the background.</li>
<li>Whether a <code>drawable</code> part is left out of its host's picture when the host is drawn whole. The page never draws both in one frame.</li></ul>
<p><a href="https://html-in-canvas.page/media-state/">Open Media controls and element state</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Video, image and chart tiles</title>
<link>https://html-in-canvas.page/media-tiles/</link>
<guid isPermaLink="true">https://html-in-canvas.page/media-tiles/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>video</category>
<category>srcset</category>
<category>svg</category>
<category>toBlob</category>
<description>A &lt;video&gt; drawn as a wall of tiles that drift apart, a figure whose image ripples under a caption of plain text, a &lt;picture&gt; whose file is picked by the size the canvas draws it at, an SVG bar chart drawn tilted with its hover styles and links working, and a script-drawn chart saved with its HTML legend as one PNG.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/media-tiles/"><img src="https://html-in-canvas.page/media-tiles/social.jpg" width="1200" height="630" alt="The page &quot;Video, image and chart tiles&quot;"></a></p>
<p><strong>Question:</strong> Do a video, an image, a picture with srcset, an inline SVG and a nested canvas keep their own behaviour (controls, file choice, :hover, links, checkboxes) when a canvas draws them in pieces, at another size or under a transform?</p>
<p><strong>Short answer:</strong> Yes for all five in Chromium 157. A whole draw in an empty clip puts the video's controls back after it is drawn as tiles, <code>sizes</code> alone moves a picture up through its files (and never down), and an affine tilt carries <code>:hover</code> and links with it. A canvas nested in a drawable figure needs <code>contain: paint</code>, or its content is drawn shifted by its offset.</p>
<p>
Five media ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>: a <code>&lt;video&gt;</code> drawn as a wall of tiles, a
<code>&lt;figure&gt;</code> whose image goes through an effect while its caption does not, a <code>&lt;picture&gt;</code> whose file is
chosen by the size the canvas draws it at, an SVG chart drawn turned and tilted with its hover styles and links working, and a
script-drawn chart exported with its HTML legend as one PNG. I wanted to know whether each media element keeps its own behaviour
(controls, <code>srcset</code>, <code>:hover</code>, links, checkboxes) when a canvas draws it in pieces, at another size or under a transform.
</p>
<h3>How it works</h3>
<p>Each demo is one 2D drawable canvas with one media element in it. The <code>paint</code> handler draws the element with <code>drawElementImage()</code>, and reads what it needs from the element at that moment.</p>
<ul>
<li><b>Media raises <code>paint</code> by itself.</b> A playing video raises it for each frame, a newly loaded image file raises it once, a CSS animation or transition inside an SVG raises it for each frame, and so does a redraw of a canvas inside a figure. The handlers ask for extra frames only for their own motion.</li>
<li><b>Pieces come from the nine-argument form.</b> <code>drawElementImage(el, sx, sy, sw, sh, dx, dy, dw, dh)</code> copies a source rectangle given in CSS pixels of the element. The wall's tiles and the ripple's rows are such pieces.</li>
<li><b>The last draw decides where input goes.</b> After pieces, the handler draws the whole element once more inside an empty clip. That adds no pixels and puts the hit region where the controls should answer.</li>
<li><b>A picture is rastered at the size it is drawn.</b> An element laid out small and drawn large is sharp, so the layout size of an image doesn't limit its drawn size. The file it shows does, which is what <code>sizes</code> is for.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, at 412 px wide with a mouse and emulated touch, at device pixel ratio 1 and 2.625. Not yet run on a phone.</p>
<ul>
<li><b>All five elements kept their own behaviour.</b> The video's controls, the caption's link and editable text, the file choice of <code>srcset</code>, the chart's <code>:hover</code> style and links, and the legend's checkboxes worked while the canvas drew the element in pieces, at another size or under a turn and a squash.</li>
<li><b>Pieces of one video drawn in one paint handler hold the same frame.</b> Two copies of one source rectangle differed by 0.00 per channel on average at device pixel ratio 1 and by at most 0.10 at 2.625, while samples 110 ms apart differed by about 11. A playing 30 fps clip raised about 30 paint events a second with no <code>requestPaint()</code>.</li>
<li><b>The hit region follows the last draw, so the wall ends with a whole draw in an empty clip.</b> After that draw the video was found at all four corners of the closed wall's box and not at the last tile. With the wall closed and the video paused there were 0 paint events in 0.7 s.</li>
<li><b>A touch tap on the closed wall showed the video's own controls</b> (emulated touch). It didn't pause the clip. The page's Pause button calls <code>pause()</code>.</li>
<li><b>An <code>&lt;img&gt;</code> and a <code>&lt;figcaption&gt;</code> are drawn separately when each is <code>drawable</code> and the figure is not.</b> The image went through <code>grayscale(1)</code> and the caption beside it stayed white. The link in the caption was found at its drawn place, and typing into the caption changed its text in the canvas.</li>
<li><b>Blends and masks reach only what is already on the canvas.</b> Each effect is drawn first on the empty canvas (<code>multiply</code>, <code>lighten</code>, <code>destination-in</code> with a dot pattern), the background is added behind with <code>destination-over</code>, and the caption is drawn last.</li>
<li><b>An element's picture is rastered at the size it is drawn.</b> A box laid out 20 px wide and drawn 320 px wide had 0 grey pixels across its black and white edge. A bitmap copy of the 20 px draw, scaled the same way, had 13. So the image is laid out once at 160 px and drawn at any width.</li>
<li><b>Writing <code>sizes</code> is enough to change the file.</b> From <code>sizes="20px"</code> to <code>"700px"</code> the browser went from the 160w file to the 1280w file and raised <code>paint</code> when it loaded, with no load listener. The required width is <code>sizes</code> times the device pixel ratio: 91 px picked 160w at ratio 1 and 320w at 2.625.</li>
<li><b>The file doesn't go back down.</b> After the 1280w file had loaded, <code>sizes="20px"</code> left <code>currentSrc</code> at 1280w, and so did a fresh copy of the <code>&lt;picture&gt;</code> element. Candidates with new URLs started from the small file again.</li>
<li><b>Writing <code>sizes</code> during a walk fetches every file on the way.</b> 160w, 320w, 640w and 1280w were fetched for one walk from 91 to 1400 px. With <code>sizes</code> written once at the end, only the first file and 1280w were fetched.</li>
<li><b>A turn and a squash are one affine matrix, and the hit region gets the same matrix.</b> The middle of a bar landed at 200.6, 90.8 under the matrix, <code>elementFromPoint()</code> returned the <code>&lt;rect&gt;</code> inside its link there, and <code>getBoundingClientRect()</code> of the <code>&lt;rect&gt;</code> gave 200.6, 90.8. The label the canvas draws over a bar is placed from that box.</li>
<li><b><code>:hover</code> on an SVG shape works under the transform and can be read in the paint handler.</b> A mouse over the Thu bar turned its pixel to the hover colour (210, 73, 31), and <code>querySelector('a.bar:hover')</code> in the handler returned it. A tap on a bar followed its <code>href</code>: <code>location.hash</code> became <code>#bar=tue</code> and the page didn't scroll.</li>
<li><b>CSS animations and transitions inside the SVG raise <code>paint</code>.</b> 30 paint events in 0.5 s for an animated <code>stroke-dashoffset</code>, 19 for a 0.3 s transition of a bar's transform, 0 for a still SVG.</li>
<li><b>A plain canvas inside a drawable figure is in the figure's picture, and redrawing it raises <code>paint</code> on the outer canvas.</b> So does unticking a checkbox from script. The export demo has no change listener: the paint handler reads the checkboxes.</li>
<li><b>The inner canvas's content is drawn at the wrong place unless the canvas has <code>contain: paint</code>.</b> With 20 px of padding round it, a canvas with a red stripe at its left edge was drawn with the stripe missing and the blue part starting at 20 px, where 30 px was expected: the content is shifted by the padding and cut by the canvas's box. With <code>contain: paint</code> or a transform on the inner canvas it was drawn at the right place. A CSS background on the same canvas wasn't shifted.</li>
<li><b>One <code>toBlob()</code> call on the outer canvas gave a PNG with the inner canvas and the HTML in it.</b> The canvas wasn't tainted. At device pixel ratio 1 the demo's PNG was 378 by 288 px and 31 kB, and <code>toBlob()</code> took 18 ms in the test browser.</li>
<li><b>A lost context shows every element as plain HTML.</b> One dispatched <code>contextlost</code> event on one canvas stopped all five and left five boxes with the video, the figure, the picture, the chart and the legend in them.</li>
<li><b>Not verified:</b> everything on a phone. In particular the speed of 12 to 40 video draws per frame, the native controls and the fullscreen button by touch, the on-screen keyboard over the caption, the file choice at the phone's pixel ratio (the line under the picture reports it), a touch drag on the chart, and Copy and Share for the PNG.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/media-tiles.md">findings/media-tiles.md</a> in the repository.</p>
<p>Five ideas from the element catalogue (group 15 of the backlog in PLAN.md). Measured in headless Chromium 157 (C157) on 2026-11-21 with a mouse and emulated touch at 412 px wide, at device pixel ratio 1 and at 2.625 (<code>--force-device-scale-factor</code>). The page's ten live checks pass at both ratios, and <code>node tools/media-tiles/check.mjs</code> drives the five demos with real input (33 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: do a video, an image, a picture with <code>srcset</code>, an inline SVG and a nested canvas keep their own behaviour (controls, file choice, <code>:hover</code>, links, checkboxes) when a canvas draws them in pieces, at another size or under a transform?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Video wall: one <code>&lt;video controls drawable&gt;</code> drawn 12 to 40 times per paint with the nine-argument <code>drawElementImage()</code>, each tile under its own translate, rotate and scale</td><td>works</td><td>Every tile is a source rectangle of the same picture.</td></tr>
<tr><td>Do all tiles hold the same video frame</td><td>yes</td><td>Two copies of one source rectangle, drawn in one handler while the clip played, differed by 0.00 per channel on average at ratio 1 and at most 0.10 at ratio 2.625 (largest single channel difference 11). Samples 110 ms apart differed by about 11 on average.</td></tr>
<tr><td>Paint events from a playing 30 fps clip, no <code>requestPaint()</code></td><td>about 30 a second</td><td>20 in 0.66 s in the live check. The wall asks for frames itself only while tiles move. Closed and paused: 0 paint events in 0.7 s.</td></tr>
<tr><td>Controls after tile draws</td><td>a whole draw inside an empty clip</td><td>Each source-rectangle draw moves the hit region to that tile. After the clipped whole draw the video was found at all 4 corners of the closed wall's box, where that draw put no pixel, and not at the last tile.</td></tr>
<tr><td>Touch tap on the closed wall</td><td>shows the native controls</td><td>Emulated touch. The clip kept playing. The wall closes on any pointer event on the canvas and stays closed for 4 s, so the controls are drawn in one piece while they are used.</td></tr>
<tr><td>Figure with a live caption: <code>&lt;figure&gt;</code> not drawable, <code>&lt;img drawable&gt;</code> and <code>&lt;figcaption drawable&gt;</code> inside it</td><td>each has its own picture</td><td>The image drawn through <code>grayscale(1)</code> was 48,48,48 and the caption beside it 255,255,255.</td></tr>
<tr><td>Caption's link and text</td><td>work at the drawn place</td><td><code>elementFromPoint()</code> on the drawn link returned the <code>&lt;a&gt;</code>. Typing into the <code>contenteditable</code> span changed the text in the canvas.</td></tr>
<tr><td>Four effects on the image only: rows moved by a sine (source rectangles), duotone (<code>ctx.filter</code> grey, then <code>multiply</code> and <code>lighten</code> fills), dots (<code>destination-in</code> with a pattern), slats (source rectangles squeezed in x)</td><td>work</td><td>Each is drawn first on the empty canvas, so a blend or a mask reaches only the image. The background goes behind with <code>destination-over</code>.</td></tr>
<tr><td>Panel behind the caption</td><td>a third draw of the image, clipped and blurred</td><td><code>ctx.filter = 'blur(7px) brightness(0.55)'</code> inside a rounded clip of the caption's box.</td></tr>
<tr><td>An element laid out 20 px wide, drawn 320 px wide</td><td>sharp</td><td>0 grey pixels across a black and white edge. A bitmap copy of the 20 px draw scaled by <code>drawImage()</code> had 13. The picture is rastered at the drawn size.</td></tr>
<tr><td>Resolution by drawn size: write the drawn width into <code>sizes</code> on the <code>&lt;source&gt;</code> and the <code>&lt;img&gt;</code>, layout unchanged</td><td>the browser picks a larger file and raises <code>paint</code></td><td><code>sizes="20px"</code> picked 160w. <code>sizes="700px"</code> picked 1280w, with 1 paint event at ratio 1 and 2 at ratio 2.625. No load listener is needed.</td></tr>
<tr><td>Device pixel ratio</td><td>multiplies</td><td><code>sizes="91px"</code> picked 160w at ratio 1 and 320w at ratio 2.625 (239 px needed).</td></tr>
<tr><td>Going back to a smaller <code>sizes</code></td><td><code>currentSrc</code> stays at the largest file loaded</td><td>Still 1280w after <code>sizes="20px"</code>, and for a fresh clone of the <code>&lt;picture&gt;</code>.</td></tr>
<tr><td>Second route to a smaller file</td><td>new URLs</td><td><code>srcset</code> rewritten with <code>?v=n</code> on every candidate started again from the small file.</td></tr>
<tr><td>Writing <code>sizes</code> on every frame of a 2.6 s walk from 91 to 1400 px</td><td>4 files fetched: 160w, 320w, 640w, 1280w</td><td>Each threshold crossed starts a fetch. Written once at the end of the walk: 2 files, the first one and 1280w.</td></tr>
<tr><td>SVG chart drawn turned and squashed (one affine matrix: a turn in the plane, then <code>cos(tilt)</code> on y)</td><td>hit region follows</td><td>The middle of a bar landed at 200.6, 90.8 under the matrix. <code>elementFromPoint()</code> returned the <code>&lt;rect&gt;</code> inside its <code>&lt;a&gt;</code> there, and not at the flat place.</td></tr>
<tr><td><code>getBoundingClientRect()</code> of a shape inside the drawn SVG</td><td>the box at the drawn place</td><td>200.6, 90.8 for the same bar. The canvas places its label from it.</td></tr>
<tr><td><code>:hover</code> on a bar under the transform, mouse</td><td>works, and can be read in the paint handler</td><td>The Thu bar's pixel became 210,73,31, its hover fill. <code>querySelector('a.bar:hover')</code> in the handler returned the bar: no pointer listener is used for the label.</td></tr>
<tr><td>Tap on a bar, which is <code>&lt;a href="#bar=tue"&gt;</code></td><td>the browser follows the link</td><td><code>location.hash</code> became <code>#bar=tue</code>, the page did not scroll, and a <code>hashchange</code> listener marks the bar.</td></tr>
<tr><td>CSS animation and transition inside the SVG</td><td>raise <code>paint</code></td><td>30 events in 0.5 s for an animated <code>stroke-dashoffset</code>, 19 for a 0.3 s transition of a bar's transform, 0 for a still SVG.</td></tr>
<tr><td>A 90 px mouse drag that starts on a bar</td><td>turns the sheet by more than 15 degrees and does not follow the link</td><td>A capture <code>click</code> listener on the canvas calls <code>preventDefault()</code> after a drag of more than 6 px. <code>location.hash</code> was unchanged after the drag.</td></tr>
<tr><td>Plain <code>&lt;canvas&gt;</code> (2D, not drawable) inside a <code>&lt;figure drawable&gt;</code></td><td>in the figure's picture</td><td>Inner pixel 0,0,208 read from the outer canvas.</td></tr>
<tr><td>Redrawing the inner canvas, no <code>requestPaint()</code> on the outer</td><td>raises <code>paint</code> on the outer canvas</td><td>1 event, pixel then 0,176,0.</td></tr>
<tr><td>Checkbox in the figure changed from script</td><td>raises <code>paint</code></td><td>The export demo has no <code>change</code> listener. The paint handler reads <code>checked</code> and redraws the ring.</td></tr>
<tr><td>Position of the inner canvas's content when the canvas is not at the figure's origin</td><td>wrong unless the canvas has <code>contain: paint</code></td><td>Figure padding 20 px, canvas with a red stripe 10 px wide at its left edge. Expected red at 20 to 29 and blue at 30 to 79. Got no red and blue at 20 to 59: the content is shifted left by the padding and cut by the canvas's box. The same upwards.</td></tr>
<tr><td>Routes tried for that</td><td><code>contain: paint</code>: right. <code>transform: translateZ(0)</code>: right. A <code>drawable</code> attribute on the inner canvas and its own draw: right. <code>will-change: transform</code>, <code>position: relative</code>, <code>willReadFrequently</code>, an <code>overflow: hidden</code> wrapper, a <code>bitmaprenderer</code> context: still shifted. A CSS background on the canvas with no context: not shifted.</td><td>Tried in a scratch page at ratio 1 and 2. The live check keeps the plain and the <code>contain: paint</code> cases.</td></tr>
<tr><td><code>toBlob()</code> on the outer canvas</td><td>one PNG with the inner canvas and the HTML</td><td>240 by 120 fixture: inner canvas 0,0,208 and HTML swatch 224,0,0 found in the decoded file, alpha 0 outside the figure. Not tainted.</td></tr>
<tr><td>The demo's export</td><td>378 by 288 px, 31 kB, 18 ms at ratio 1</td><td>The PNG has the size of the outer canvas's buffer (994 by 757 at ratio 2.625). A download with the name <code>chart-and-legend.png</code> was received by the test browser.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One dispatched <code>contextlost</code> event on one canvas stops all five and shows the video, the figure, the picture, the chart and the legend as plain elements (5 boxes).</td></tr>
<tr><td>Memory</td><td>2.3 MB in 7 canvases at ratio 1; 3.1 MB and 0.78 megapixels at load at ratio 2.625 (<code>check:jank</code>)</td><td>Five 2D canvases, no WebGL, no readback outside a tap or a live check.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>&lt;source&gt;</code> needs its own <code>sizes</code>. With <code>sizes</code> only on the <code>&lt;img&gt;</code>, the <code>&lt;source&gt;</code> used the default of <code>100vw</code> and the page loaded the 1280w file at once.</li>
<li>The inner canvas offset. The ring chart was cut on its left and top edges, and the export was too. A fixture in which the inner canvas sat at the figure's origin did not show it. The check that found it draws a stripe at the canvas's edge and has padding round the canvas.</li>
<li>At ratio 2.625 two draws of the same video source rectangle at different places are not bit-identical (up to 11 in one channel, 0.10 on average). The check compares the average with the difference between two frames.</li>
<li>Resource Timing reported the first file twice at ratio 2.625. The list of fetched files is made of distinct URLs.</li>
<li>The Python test server has no Range support, so the wall loads its clip as a blob. Seeking from the native timeline then works on any server.</li>
<li>The loupe on the resolution demo is a source-rectangle draw of the same image, so it moved the image's hit region to the loupe. The picture's place is given back with a clipped draw.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: all five by touch. Open <code>/media-tiles/</code> and try each.</li>
<li>The speed of 12, 24 and 40 video draws per frame on a phone GPU, and of the ripple (about 30 source-rectangle draws per frame).</li>
<li>The native video controls by touch: the centre play button, the timeline, the overflow menu and fullscreen from the closed wall.</li>
<li>The on-screen keyboard over the caption, and text selection in the caption by long press.</li>
<li>The file picked at the phone's device pixel ratio. The line under the picture reports <code>sizes</code>, the ratio and <code>currentSrc</code>.</li>
<li>Whether Chrome on Android also keeps the largest file when <code>sizes</code> shrinks.</li>
<li>A sideways touch drag on the chart (the canvas has <code>touch-action: pan-y</code>). The drag was driven with a mouse only.</li>
<li><code>:hover</code> after a tap on a touch screen. The tap route through the link was measured, the hover route was measured with a mouse.</li>
<li>Copy (<code>ClipboardItem</code> with a promise) and Share (<code>navigator.share()</code> with a file). Neither can be confirmed in the headless browser.</li>
<li>A screen reader on any of the five.</li></ul>
<p><a href="https://html-in-canvas.page/media-tiles/">Open Video, image and chart tiles</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Live minimap of a page</title>
<link>https://html-in-canvas.page/minimap/</link>
<guid isPermaLink="true">https://html-in-canvas.page/minimap/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>article drawable</category>
<category>drawElementImage</category>
<category>updateElementGeometry</category>
<category>scroll container</category>
<description>A scrolling column of articles in a canvas, with every article drawn a second time at a sixth of its size in a strip beside it. The strip is the live elements: typing, a running build log and added articles show in it at once. An overview flies the articles out to a grid.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/minimap/"><img src="https://html-in-canvas.page/minimap/social.jpg" width="1200" height="630" alt="The page &quot;Live minimap of a page&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw the articles of a scrolling page twice, once to read and once as a minimap, and keep native scrolling and input?</p>
<p><strong>Short answer:</strong> Yes, with one choice to make. If the scroll container isn't drawable the pictures are whole and the page has to do the scrolling. If it's drawable the browser scrolls it and an article that repaints while half out of view loses the hidden half.</p>
<p>
A scrolling column of articles inside a canvas. Each <code>&lt;article&gt;</code> is drawn twice: at full size in the reading area, and at about a sixth of its size in the strip on the right.
The strip is drawn from the same live elements, so typing in the note, running the build or adding an article changes it at once.
Scroll the column by touch or wheel. Drag or tap in the strip to move the view. <b>Overview</b> flies every article out to a grid, and a tap on one flies back to it.
</p>
<h3>How it works</h3>
<p>Every article has <code>drawable</code>. The scroll container around them is laid out and scrolls, and has no picture. The picture of an article is the whole article, also when it's scrolled out of view. That's what lets the strip show the full page.</p>
<p>On each <code>paint</code> event the canvas draws the rail, then every article at the strip's scale, then a frame for the part in view. After that it draws the articles that are in view at full size, at <code>offsetTop - scrollTop</code>, clipped to the reading area.
An element's hit region is where it was drawn last, so articles in view take input in the reading area. An article out of view was last drawn in the strip. Its hit region is shrunk to a point with <code>updateElementGeometry()</code>, so the strip's input goes to the rail.</p>
<p><b>Scrolling has two routes, and the menu under the demo switches between them.</b></p>
<p>Route 1, the default: the scroll container isn't drawable. Chromium then doesn't scroll it for a wheel or a touch drag. The input goes to the page. The events still reach the container, because they bubble from the article that was hit.
The page sets <code>scrollTop</code> from the wheel delta and from touch movement, keeps moving after the finger lifts, and passes what is left over to the page when the container is at an end. Page Up and Page Down scroll it without help.</p>
<p>Route 2: the scroll container has <code>drawable</code> too and is drawn with no alpha, which gives it a hit region. The browser scrolls it. The cost is in the pictures. An article is now a drawable element inside a drawable element, and Chromium records only the part of it that is inside the container's box at that moment.
An article that changes while it's half out of view loses the hidden half in the strip, and the hole stays until the article changes again while fully in view. Switch to this route, scroll an article half out, press "New numbers" and look at the strip.</p>
<p>The rail is an empty element with <code>touch-action: none</code>, <code>role="scrollbar"</code> and a tab stop. Its hit region covers the strip. A drag on it sets <code>scrollTop</code>. Arrow keys, Page Up and Page Down work when it has focus.</p>
<p>The minimap covers the articles in this canvas only. An element can be drawn only into the canvas it is inside, so a minimap of the whole document would need the whole document inside one canvas.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 a <code>drawable</code> article inside a scroll container that isn't drawable keeps a whole picture wherever it is scrolled to, and when part of the canvas is outside the window. Changes to an article that is out of view show in the strip.</li>
<li>The browser doesn't scroll that container for a wheel or a touch drag on a drawn article. The page scrolls instead. <code>will-change</code>, a transform, <code>contain: paint</code> and <code>overflow: scroll</code> on the container made no difference. Keyboard scrolling and <code>scrollTop</code> work.</li>
<li>A <code>wheel</code> listener on that container is treated as passive: the event isn't cancelable and the page scrolls too. The same listener on the canvas can call <code>preventDefault()</code>. <code>touch-action: none</code> on the container does stop the page panning.</li>
<li>With <code>drawable</code> on the container as well, wheel and touch scroll it natively once it has a hit region. Its own picture leaves the articles out.</li>
<li>On that route an article's picture is cut to what was inside the container's box, and inside the window, when the article was last painted. The missing part is transparent, <code>drawElementImage()</code> doesn't throw, and scrolling or <code>requestPaint()</code> doesn't bring it back. A style change on the article while it's fully in view does. This is the reason the page defaults to route 1.</li>
<li>An article that was last drawn in the strip takes taps in the strip. The page parks it with <code>updateElementGeometry()</code> at a scale of 0.001.</li>
<li><code>touch-action</code> is per element: <code>none</code> on the rail and on the scripted scroll container, the default on the native one.</li>
<li>Not verified: how the scripted touch scrolling feels on a phone next to native scrolling, and the on-screen keyboard over the note field.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/minimap.md">findings/minimap.md</a> in the repository.</p>
<p>Measured in C157 (headless shell) on 2026-11-21, with a mouse wheel and with CDP touch events at 412 px. Not yet run on A159.</p>
<p>The page has two structures and a menu to switch between them. In both, every <code>&lt;article&gt;</code> has <code>drawable</code> and is drawn twice per frame: small in the strip, then at full size in the reading area.</p>
<table><thead><tr><th>Question</th><th>Scroll container not drawable (default)</th><th>Scroll container drawable</th></tr></thead><tbody><tr><td>Picture of an article scrolled out of view</td><td>whole</td><td>whole, if it has not repainted while cut (next row)</td></tr>
<tr><td>Article repaints while half outside the reading area</td><td>whole</td><td>the hidden half is transparent</td></tr>
<tr><td>Article repaints while its drawn position is in a part of the canvas outside the window</td><td>whole</td><td>empty</td></tr>
<tr><td>Does the hole heal</td><td>does not occur</td><td>Not on scroll and not on <code>requestPaint()</code>. A style change on the article while it is fully in view records it whole again. <code>remove()</code> and insert again did not. A clone was whole.</td></tr>
<tr><td>Wheel on a drawn article</td><td>goes to the page. The container does not scroll.</td><td>scrolls the container</td></tr>
<tr><td>Touch drag on a drawn article</td><td>pans the page</td><td>scrolls the container</td></tr>
<tr><td>Page Down from a focused control inside, <code>scrollTop</code> from script</td><td>scroll the container</td><td>scroll the container</td></tr>
<tr><td><code>wheel</code> listener on the container</td><td>runs, but the event is not cancelable and the page scrolls too</td><td>not needed</td></tr>
<tr><td><code>wheel</code> listener on the canvas</td><td>cancelable. The page uses this one.</td><td>not needed</td></tr>
<tr><td><code>touch-action: none</code> on the container</td><td>stops the page panning</td><td>not wanted</td></tr></tbody></table>
<p>Other results:</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A drawable scroll container's own picture</td><td>background only</td><td>Its drawable articles are left out.</td></tr>
<tr><td>Scrolling a drawable container by script</td><td>raises one <code>paint</code> event</td><td>With no <code>requestPaint()</code>.</td></tr>
<tr><td>An article drawn at a sixth of its size</td><td>hit at the small copy</td><td>So an article that is out of view takes taps in the strip, where it was last drawn.</td></tr>
<tr><td><code>updateElementGeometry()</code> with a scale of 0.001</td><td>takes it out of hit testing</td><td>The strip's input then reaches the rail element.</td></tr>
<tr><td><code>will-change</code>, <code>transform: translateZ(0)</code>, <code>contain: paint</code>, <code>isolation</code>, <code>overflow: scroll</code>, a background, <code>overscroll-behavior</code> on the non-drawable container</td><td>no change</td><td>Wheel still scrolls the page.</td></tr>
<tr><td>Changes to an article that is out of view (text, background, added lines)</td><td>show in the strip</td><td>Both structures.</td></tr></tbody></table>
<p>What the page does: the default structure, with scrolling by script. Wheel deltas and touch movement set <code>scrollTop</code>, a short coast follows a touch drag, and what is left over at either end is passed to <code>window.scrollBy()</code> during the drag.</p>
<h3>Things that bit</h3>
<ul><li>The first version used the drawable container. One article was blank in the strip and in the reading area from page load. It was the one whose drawn position was inside the canvas and below the bottom of the window. Changing its content, toggling <code>drawable</code>, <code>display</code> and removing and inserting it again while the page was at the top did not bring it back.</li>
<li>The same article was whole with <code>?nohold</code> and with a taller window, which hid the cause for a while.</li>
<li>A probe that read alpha from the strip always read 255, because the rail's background is under the copies. Read colour.</li></ul>
<h3>Not verified</h3>
<ul><li>How the scripted touch scrolling feels on a phone next to native scrolling. Opening <code>/minimap/</code> on the phone and switching the "Scroll container" menu compares the two.</li>
<li>The on-screen keyboard over the note field.</li>
<li>Whether Chrome 159 still cuts the picture of a nested drawable. The check "The same with drawable on the scroll container" on the page reports it on the device that opens it.</li></ul>
<h3>Ideas built</h3>
<ul><li>"Live minimap of a page" from <code>public/elements/ideas.js</code> (structure). The strip is a sixth of full size at 412 px, not a tenth: it is as wide as a thumb needs.</li></ul>
<h3>Open ideas</h3>
<ul><li>A minimap of the whole document. It needs every article of the page inside one canvas, which the site's page skeleton does not allow. A stand-alone page could try it.</li>
<li>Search hits and text selections marked in the strip, from <code>Range.getClientRects()</code>.</li></ul>
<p><a href="https://html-in-canvas.page/minimap/">Open Live minimap of a page</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Rewind to video, and two pointers on moving pieces</title>
<link>https://html-in-canvas.page/motion-capture/</link>
<guid isPermaLink="true">https://html-in-canvas.page/motion-capture/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>ElementImage</category>
<category>VideoEncoder</category>
<category>updateElementGeometry</category>
<category>pointer events</category>
<description>The history kept by &lt;dom-rewind&gt; is encoded to a video file with WebCodecs, and eight moving pieces of HTML are pressed with two fingers at once to see which piece the browser sends each pointer to.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/motion-capture/"><img src="https://html-in-canvas.page/motion-capture/social.jpg" width="1200" height="630" alt="The page &quot;Rewind to video, and two pointers on moving pieces&quot;"></a></p>
<p><strong>Question:</strong> Can the recorded past of live HTML be encoded as video, and can two pointers at once each reach the moving piece under them?</p>
<p><strong>Short answer:</strong> Yes to the first: <code>frames()</code> gives bitmaps that a <code>VideoEncoder</code> accepts, and the WebM plays. For the second, one element has one hit box, so only one pointer is right. One element for each piece, or a canvas that routes each pointer itself, makes both right.</p>
<p>
Two experiments that were left open on <a href="https://html-in-canvas.page/time-scrubber/">the time scrubber</a> and <a href="https://html-in-canvas.page/particles/">the text particles</a>.
The first encodes the recorded past of live HTML as a video file. The second presses moving pieces of HTML with two pointers at once and reports which piece the browser sent each one to.
</p>
<h3>How it works</h3>
<p>
<strong>Experiment 1.</strong> <code>&lt;dom-rewind&gt;</code> stores, for each frame, an <code>ElementImage</code> of every child and where it was drawn. Its <code>frames()</code> method draws each stored frame again and yields an <code>ImageBitmap</code>.
<code>encodeRewind()</code> draws the bitmap on a plain canvas, makes a <code>VideoFrame</code> and encodes it. The work isn't real time: four seconds of history can take less or more than four seconds.
The second button is the other route: the element replays the history on screen and <code>MediaRecorder</code> records the canvas stream while it plays, which takes exactly as long as the clip.
</p>
<p>
<strong>Experiment 2.</strong> The browser picks the target of a <code>pointerdown</code> before any script runs, using the hit boxes as they are at that moment. A <code>drawable</code> element has one hit box, set by the last draw or by <code>updateElementGeometry()</code>.
When one element is drawn in eight places, seven of them have no hit box. A nine-argument draw also limits the hit box to the rectangle that was drawn, so the canvas ends each paint with a draw of the whole element at alpha 0. One element for each pad gives each place its own. The third mode keeps one element and does the browser's part in script: for each pointer it moves the box, asks what is there and dispatches a copy of the event.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The recorded past of HTML can be encoded as video.</strong> <code>frames()</code> gives one <code>ImageBitmap</code> for each past frame, a <code>VideoFrame</code> is made from a plain canvas copy, and the VP9 or VP8 chunks go into a WebM file that a <code>&lt;video&gt;</code> plays. The drawable canvas is never read with <code>getImageData()</code>.</li>
<li><strong>The encoder route isn't tied to real time.</strong> It encodes history that was never recorded as video. In headless Chromium 157, 121 frames at 720 by 568 took 0.6 s for 4 s of video. VP9, VP8, AV1 and H.264 encoders all accepted the frames and their output decoded back to the same number of frames. The <code>MediaRecorder</code> route has to replay the history on screen and takes as long as the clip.</li>
<li><strong>A video has no live content.</strong> The file holds pictures. The button in it can't be pressed and the clock doesn't run.</li>
<li><strong>One <code>drawable</code> element answers for one place at a time.</strong> With every pad in one element, three two-finger presses on six pads reached one pad (headless Chromium 157, touches sent through the DevTools protocol). None of the three second fingers reached its pad.</li>
<li><strong>A <code>pointerdown</code> is decided before the hit box can move, a <code>click</code> is not.</strong> A single tap on a pad that the hit box wasn't under ran no <code>pointerdown</code> listener, but the <code>click</code> that followed went to the right pad, because the canvas had moved the box in between. Two fingers down at once produce no <code>click</code>.</li>
<li><strong>One element for each piece makes two pointers right.</strong> Each piece has its own hit box, placed with <code>updateElementGeometry()</code> every frame. The same six presses reached six pads.</li>
<li><strong>A canvas can route pointers itself with one element.</strong> It moves the hit box under each pointer in turn and asks <code>elementFromPoint()</code>. Six of six presses reached their pad, and the browser's own target was wrong for four of them. The pad receives a copy of the event, so <code>isTrusted</code> is false, the browser's own pointer capture stays with its first target and <code>:active</code> doesn't apply.</li>
<li><strong>A nine-argument draw limits the hit box to its source rectangle.</strong> After drawing parts of an element, only the last part drawn takes hits, wherever <code>updateElementGeometry()</code> puts the box. A further draw of the whole element at alpha 0 makes all of it take hits again.</li>
<li><strong>A moved hit box needs an attribute change before the next question.</strong> Without it, <code>elementFromPoint()</code> at a point that was asked before gives the old answer.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/motion.md">findings/motion.md</a> in the repository.</p>
<h3>Rewind to video, and two pointers on moving pieces (<code>/motion-capture/</code>)</h3>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21, by the page's live checks and by a Playwright script that sent real touches through the DevTools protocol (<code>Input.dispatchTouchEvent</code>, two touch points) at 412 px wide and a device scale factor of 2.625. Builds backlog group 25. Files: <code>public/motion-capture/</code> (<code>index.html</code>, <code>rewind-encode.js</code>, <code>pieces.js</code>), and <code>#region frames</code> comments in <code>lib/dom-rewind.js</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>&lt;dom-rewind&gt;.frames()</code> fed to <code>VideoEncoder</code></td><td>works</td><td>Each bitmap is drawn over a background colour on a plain <code>OffscreenCanvas</code>, a <code>VideoFrame</code> is made from that canvas and encoded. 121 frames at 720 by 568 took 5.0 ms each (0.6 s of work for 4 s of video, 680 kB as VP9).</td></tr>
<tr><td>The WebM file in a <code>&lt;video&gt;</code></td><td>plays</td><td><code>lib/webm-mux.js</code> writes the VP9 or VP8 chunks. The check loads the file, reads its size and duration, seeks to the start and the end and finds the card on the left and then on the right.</td></tr>
<tr><td>VP9, VP8, AV1, H.264 encoders</td><td>all four accept the frames</td><td>Each output is decoded back with <code>VideoDecoder</code>: 11 frames in, 11 out, the first and last pictures are right. AV1 and H.264 have no container in this project, so the page shows the last decoded frame and no file.</td></tr>
<tr><td><code>MediaRecorder</code> on the canvas stream while <code>replay()</code> runs</td><td>works, in real time</td><td>4.0 s for 4 s of video, 893 kB. The history has to be played on screen.</td></tr>
<tr><td>Two fingers on two pads, every pad in one <code>drawable</code> element</td><td>1 of 6 presses reached its pad, 0 of 3 second fingers</td><td>The element has one hit box. The browser picks the target of <code>pointerdown</code> before a script can move it.</td></tr>
<tr><td>A single tap on a pad the hit box is not under</td><td><code>pointerdown</code> misses, <code>click</code> arrives at the right pad</td><td>The canvas moves the box in its <code>pointerdown</code> capture listener and the browser hit tests again for the <code>click</code>. Two fingers down at once give no <code>click</code>.</td></tr>
<tr><td>One <code>drawable</code> element for each pad</td><td>6 of 6</td><td>Eight hit boxes, each placed with <code>updateElementGeometry()</code> in every paint.</td></tr>
<tr><td>One element, the canvas routes each pointer (moves the box, toggles an attribute, asks <code>elementFromPoint()</code>, dispatches a copy)</td><td>6 of 6, the browser's own target was wrong for 4</td><td>The pad's listener gets an untrusted copy. Pointer capture and <code>:active</code> stay with the browser's target.</td></tr>
<tr><td>Hit testing an element that was drawn in parts with nine-argument draws</td><td>only the last source rectangle drawn takes hits</td><td>With the box put under pad A by <code>updateElementGeometry()</code>, the point on A answers the canvas. A last draw of the whole element at <code>globalAlpha</code> 0 makes the whole element take hits.</td></tr>
<tr><td><code>elementFromPoint()</code> after <code>updateElementGeometry()</code> with no attribute change</td><td>old answer</td><td>Same as the earlier finding on <code>/view-transitions/</code>.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li><code>&lt;meta name="checks" content="tap"&gt;</code> makes <code>?checks</code> wait as well. Automation uses <code>?autochecks=1</code>.</li>
<li><code>&lt;dom-rewind&gt;</code> records a frame only when something changed, so a still fixture has one frame however long it waits.</li>
<li><code>onprogress?.(++i)</code> does not count when there is no callback: the argument of an optional call that is skipped is not evaluated.</li>
<li>A capture listener that queues a microtask runs it before the target's own listener, because the microtask checkpoint comes after each listener.</li></ul>
<h4>Not verified</h4>
<ul><li>Everything on a phone. Hardware encoders can refuse odd sizes or these codec strings: the Codec list on the page shows what the device accepts, and the checks encode with each one. Run the live checks on the phone.</li>
<li>Whether <code>captureStream()</code> on a drawable canvas (the MediaRecorder button) is safe on the Android phone that lost canvases with <code>willReadFrequently</code>. It runs only on a tap.</li>
<li>Real fingers. The two-finger numbers come from touches sent by the DevTools protocol. The status line under experiment 2 counts presses on the device.</li>
<li>Three or more pointers, and a pen with a finger.</li>
<li><code>npm run check:jank -- --checks /motion-capture/</code> reports 10 blank frames while the checks build and remove fixtures in the bottom panel. The page's checks wait for a tap, and the default run passes.</li></ul>
<h4>For the index</h4>
<ul><li>Capture: the history of <code>&lt;dom-rewind&gt;</code> encodes to WebM through <code>frames()</code>, <code>VideoFrame</code> and <code>VideoEncoder</code> without reading the drawable canvas (<code>/motion-capture/</code>, C157, measured).</li>
<li>Hit testing: one <code>drawable</code> element has one hit box, so a second simultaneous pointer misses; one element for each piece, or routing in a capture listener, fixes it (<code>/motion-capture/</code>, C157, measured).</li>
<li>Hit testing: a nine-argument <code>drawElementImage()</code> limits the element's hit region to the source rectangle of the last draw (<code>/motion-capture/</code>, C157, measured).</li>
<li>Hit testing: <code>click</code> after a tap is hit tested again and follows a box moved during <code>pointerdown</code> (<code>/motion-capture/</code>, C157, measured).</li></ul>
<h4>API requests</h4>
<ul><li>A way to give one element several hit regions, one for each place it is drawn, for example <code>updateElementGeometry()</code> accepting a list of source rectangle and transform pairs.</li></ul>
<h4>Open ideas</h4>
<ul><li>An MP4 writer so that H.264 and AV1 output becomes a file.</li>
<li>Sound in the export: page sounds recorded with their times and mixed in with <code>AudioEncoder</code>.</li>
<li><code>setPointerCapture()</code> on the routed element, to see whether later events of that pointer can be made trusted.</li></ul>
<p><a href="https://html-in-canvas.page/motion-capture/">Open Rewind to video, and two pointers on moving pieces</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>DOM elements in egui and Qt Quick</title>
<link>https://html-in-canvas.page/native-ui/</link>
<guid isPermaLink="true">https://html-in-canvas.page/native-ui/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>Two native UI toolkits compiled to WebAssembly, each with real &lt;input&gt; and &lt;select&gt; elements laid out and drawn by the toolkit. Plus notes on Flutter, Compose and others.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/native-ui/"><img src="https://html-in-canvas.page/native-ui/social.jpg" width="1200" height="630" alt="The page &quot;DOM elements in egui and Qt Quick&quot;"></a></p>
<p><strong>Question:</strong> Can a native UI toolkit compiled to WebAssembly (egui, Qt Quick) use real DOM inputs as widgets inside its own WebGL canvas?</p>
<p><strong>Short answer:</strong> Yes for both, with a bridge of about 200 lines and no change to the toolkit. Tab order and occlusion are left to the bridge.</p>
<p>
egui (Rust) and Qt Quick (C++) are native UI toolkits. Compiled to WebAssembly they draw every widget themselves into one WebGL canvas,
so the page has no real inputs. Here both apps contain real <code>&lt;input&gt;</code>, <code>&lt;select&gt;</code> and <code>&lt;textarea&gt;</code>
elements. The toolkit lays them out and draws them from a texture filled by <code>texElementSubImage2D()</code>. The browser handles their input.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Both toolkits took a DOM element as a widget without changes to the toolkit.</strong> egui needs a paint callback (<code>egui_glow::CallbackFn</code>). Qt Quick needs a <code>QQuickItem</code> whose node wraps a GL texture (<code>QSGOpenGLTexture::fromNative()</code>). Each bridge is about 200 lines.</li>
<li><strong>The element is drawn by the toolkit, so it is in the toolkit's z-order.</strong> An egui window covers the DOM fields, an egui scroll area clips them, and Qt Quick rotates and fades them. Toolkits that put HTML over or under the canvas can't do this.</li>
<li><strong>Layout goes both ways.</strong> The toolkit sets the element's width, the browser lays it out, and the toolkit reads <code>offsetHeight</code> to size its widget. The paragraph of DOM text wraps to the width egui gives it.</li>
<li><strong>The browser doesn't know what the toolkit draws on top.</strong> An element is hit tested wherever its geometry is. The egui bridge asks egui (<code>Context::layer_id_at()</code>) in a capture-phase listener before an event reaches an element, and moves the element's geometry off the canvas when an egui window is over it at the pointer. The Qt proof doesn't do this yet.</li>
<li><strong>Two things on the page want each event.</strong> egui listens on the canvas and Qt on its window element, and an event on a child element bubbles to both. The bridges stop propagation at the element. egui already ignores pointer moves when <code>elementFromPoint()</code> isn't its canvas, which helped.</li>
<li><strong>Focus is split.</strong> Tab moves between the DOM fields in DOM order and between toolkit widgets in the toolkit's order, and the two orders aren't joined. A click hands focus over correctly in both directions.</li>
<li><strong>The texture must be premultiplied.</strong> egui and Qt Quick both blend premultiplied alpha. Without <code>UNPACK_PREMULTIPLY_ALPHA_WEBGL</code> text on a transparent background is drawn too heavy.</li>
<li><strong>Qt's canvas is in a shadow root and Qt creates it.</strong> The element has to be moved in after Qt has a GL context, and it needs inline styles. Setting <code>content="drawable"</code> on a canvas that already has a WebGL context works.</li>
<li><strong>Raw GL inside Qt Quick's frame prints warnings.</strong> Chromium logs five <code>texParameter: no texture bound</code> warnings per item at start-up, from Qt's renderer after the foreign texture is wrapped. The textures are drawn correctly. Not investigated further.</li>
<li><strong>Some of what the browser paints for a field is left out of the texture.</strong> The explainer excludes spelling and grammar markers, pending autofill previews, IME pop-ups and IME composition formatting from element images for privacy. The textarea has <code>spellcheck</code> on and a misspelt word, and no marker is drawn.</li>
<li><strong><code>updateElementGeometry()</code> doesn't drop cached hit-test results.</strong> In Chromium 157, <code>elementFromPoint()</code> at a point that was hit tested just before the call keeps returning the old element, while a point two pixels away is correct. Any DOM mutation clears it, so both bridges toggle an attribute on the canvas after each geometry update.</li>
<li><strong>eframe focuses its hidden text input when it starts.</strong> The page makes <code>focus()</code> a no-op while the app starts so that opening the page doesn't move focus.</li>
<li><strong>Not verified on a phone.</strong> Both apps were tested in headless Chromium 157 at a 2.625 device scale with touch events. DevTools device emulation gives egui a wrong scale (it reads a canvas size that isn't in device pixels), so use a real phone. Touch-dragging on a DOM field doesn't scroll the egui scroll area under it.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/native-ui.md">findings/native-ui.md</a> in the repository.</p>
<p>Tested in headless Chromium 157 at 1× and at a 2.625 device scale with touch. egui 0.37 (eframe, glow, WebGL2) and Qt Quick 6.10.3 (Emscripten 4.0.7, WebGL2). Sources in <code>native/</code>. The survey of other frameworks and the list of what would have to change is <code>docs/native-frameworks.md</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>DOM element as an egui widget, drawn by an <code>egui_glow::CallbackFn</code> paint callback</td><td>works</td><td><code>texElementSubImage2D</code> into a texture bound by Rust, inside egui's own WebGL pass. An egui window covers it and an egui scroll area clips it.</td></tr>
<tr><td>DOM element as a Qt Quick item</td><td>works</td><td>A <code>QQuickItem</code> with a <code>QSGSimpleTextureNode</code> over <code>QSGOpenGLTexture::fromNative()</code>. Uploaded on <code>QQuickWindow::beforeRendering</code>. Qt's <code>opacity</code> and <code>rotation</code> apply.</td></tr>
<tr><td><code>content="drawable"</code> set on a canvas after the toolkit made its WebGL context</td><td>works</td><td>Both toolkits create the context before the bridge runs.</td></tr>
<tr><td>Element moved into Qt's canvas, which is in a shadow root</td><td>works</td><td>Page stylesheets do not apply there, so the page copies computed styles inline first.</td></tr>
<tr><td>Toolkit sets the width, browser reports the height</td><td>works</td><td><code>style.width</code>, then <code>offsetHeight</code>. One frame late.</td></tr>
<tr><td>Typing, caret, Tab between DOM fields, click from a toolkit field to a DOM field and back</td><td>works</td><td>Events are stopped at the element so the toolkit does not also handle them.</td></tr>
<tr><td>Hit testing a field rotated by Qt Quick</td><td>works</td><td><code>QQuickItem::itemTransform()</code> passed to <code>updateElementGeometry()</code>.</td></tr>
<tr><td>A toolkit window drawn over a DOM field</td><td>needs a guard</td><td>The browser still hits the field. The egui bridge asks <code>Context::layer_id_at()</code> before the event is delivered.</td></tr>
<tr><td>Tab from a DOM field to a toolkit widget</td><td>fails</td><td>The toolkit's widgets are not DOM nodes.</td></tr>
<tr><td>Upload without <code>UNPACK_PREMULTIPLY_ALPHA_WEBGL</code></td><td>wrong</td><td>Text on a transparent background is too heavy, because both toolkits blend premultiplied alpha.</td></tr>
<tr><td>Spelling markers on a <code>spellcheck</code> textarea in the texture</td><td>not drawn</td><td>The explainer excludes them from element images.</td></tr>
<tr><td><code>elementFromPoint()</code> at a point hit tested just before <code>updateElementGeometry()</code> moved the element away</td><td>stale (Chromium 157)</td><td>Returns the old element; a point 2px away is correct. A DOM mutation clears it, so the bridges toggle an attribute on the canvas after each geometry update. Possible browser bug.</td></tr>
<tr><td>eframe under DevTools device emulation</td><td>wrong scale</td><td>The canvas buffer stays at CSS size while egui uses the device pixel ratio. <code>--force-device-scale-factor</code> is correct.</td></tr>
<tr><td>eframe start-up</td><td>takes focus</td><td>It focuses its hidden text input. The page makes <code>focus()</code> a no-op while the app starts.</td></tr>
<tr><td>Raw GL in Qt Quick's frame</td><td>warnings</td><td>Five <code>texParameter: no texture bound</code> warnings per item at start-up. Textures draw correctly.</td></tr></tbody></table>
<p>Not verified: a real phone, IME composition, where native pickers open for a rotated field, screen readers, Qt Widgets (2D canvas, <code>putImageData</code>).</p>
<p><a href="https://html-in-canvas.page/native-ui/">Open DOM elements in egui and Qt Quick</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Navigations drawn by a shader</title>
<link>https://html-in-canvas.page/nav-shader/</link>
<guid isPermaLink="true">https://html-in-canvas.page/nav-shader/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Navigation API</category>
<category>precommitHandler</category>
<category>sourceElement</category>
<category>WebGPU</category>
<description>A four-page site in one canvas. The Navigation API intercepts each link, form, Back and Forward, fetches the new page before the URL changes, and a shader spreads it from the element that was tapped. Both pages are live while it runs.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/nav-shader/"><img src="https://html-in-canvas.page/nav-shader/social.jpg" width="1200" height="630" alt="The page &quot;Navigations drawn by a shader&quot;"></a></p>
<p><strong>Question:</strong> Can the Navigation API drive a canvas transition between two live views: load the new view before the URL changes, and start the shader from the element that was clicked?</p>
<p><strong>Short answer:</strong> In Chromium 157 the precommit handler loads the new view as a canvas child before the URL changes, sourceElement gives the shader its origin, and both views take input while the shader blends them. WebGPU isn't verified.</p>
<p>
A four-page site inside one canvas. Tap a card or a link: the address changes, and a shader spreads the new page from the element you
tapped. Back and Forward do the same. Both pages are live DOM while the shader runs.
</p>
<h3>How it works</h3>
<p>
<a href="https://html-in-canvas.page/transitions/"><code>&lt;live-transition&gt;</code></a> draws its children in one canvas and blends two of them with a fragment
shader, with WebGPU when it works and WebGL otherwise. This page adds the navigation. One <code>navigate</code> listener intercepts links, the
GET form, Back and Forward. Its <code>precommitHandler</code> fetches the new view's HTML and appends it as a child, which defers the URL
change until the view is ready. Its post-commit handler calls <code>show()</code> with the centre of <code>event.sourceElement</code> as the
origin, and the navigation is finished when the shader has finished.
</p>
<p>
Views are kept after they are first loaded, so text typed into one is there on the way back. Reloading at
<code>?view=knots</code> starts on that view.
</p>
<h3>Findings</h3>
<ul>
<li><b>Measured, headless Chromium 157, 21 November 2026.</b> <code>precommitHandler</code>, <code>controller.addHandler()</code> and <code>NavigateEvent.sourceElement</code> are all present. The first two were listed for Chrome 141 and 146.</li>
<li><b>The new view can be a live child of the canvas before the address changes.</b> The precommit handler fetched and appended the view in 84 ms and the query string was still the old one when it resolved. The post-commit handler then started the shader.</li>
<li><b><code>sourceElement</code> gives the shader its origin.</b> For a link it is the <code>&lt;a&gt;</code>, for the GET form it is the submit button. <code>getBoundingClientRect()</code> on it, minus the element's own rect, was within 2 px of the card centre. Back and Forward have no source element, so they start from the centre.</li>
<li><b>Both views run while the shader blends them.</b> At 41% of a 4 s transition the old view's clock had counted on and a text field in the new view took a value. A tap part way through goes to whichever view the shader shows at that point (the <code>pick</code> function of the effect).</li>
<li><b>Back and Forward are intercepted the same way.</b> A traversal was drawn by the shader. A view is kept as a child after its first load, so its precommit step took 0 ms and its form state was still there.</li>
<li><b>A snapshot outlives its element.</b> An <code>ElementImage</code> taken with <code>captureElementImage()</code> still drew after the element was removed. This page doesn't need it, because the old view stays in the DOM, but a site that discards the old view could keep its picture this way.</li>
<li><b>The hidden copy that runs the navigating checks shares this tab's history.</b> <code>history.length</code> went from 2 to 4 while the checks ran. After the copy was removed, one Back from a view returned to the first view, so the copy's entries weren't visited. When the same checks ran during a visitor's own navigation, the copy's <code>history.back()</code> undid the visitor's navigation, which is why the checks on this page wait for a tap.</li>
<li><b>Not verified.</b> WebGPU on screen (no adapter here: the WGSL of the ink shader hasn't been compared with the GLSL), the phone's Back gesture and its preview animation, a cross-document navigation, and what a screen reader says when the view changes. The WebGPU check above compares the two pictures on a device that has an adapter.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/nav-shader.md">findings/nav-shader.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 on 2026-11-21. A four-view site is the children of one <code>&lt;live-transition&gt;</code>; a <code>navigate</code> listener turns each same-page navigation into a shader transition.</p>
<table><thead><tr><th>What</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td><code>NavigationPrecommitController</code>, <code>controller.addHandler()</code>, <code>NavigateEvent.sourceElement</code></td><td>present</td><td>All three in Chromium 157.</td></tr>
<tr><td>Fetch the new view and append it as a canvas child in <code>precommitHandler</code></td><td>works</td><td>The view loaded in 45 to 91 ms while <code>location.search</code> was still the old query. The URL changed after the promise resolved.</td></tr>
<tr><td>The transition origin from <code>sourceElement</code></td><td>works</td><td>The link's <code>getBoundingClientRect()</code> centre, minus the element's rect, was within 2 px of the card centre. A GET form gives its submit button. A traversal has no source element.</td></tr>
<tr><td>Both views live while the shader blends them</td><td>works</td><td>At 41% of a 4 s transition the old view's clock had counted from 0 to 2 s and a text field in the new view took a value.</td></tr>
<tr><td>Back intercepted and drawn</td><td>works</td><td>One <code>traverse</code> navigation ran the shader. The view was already a child, so its precommit step took 0 ms.</td></tr>
<tr><td><code>drawElementImage()</code> of a snapshot after its element was removed</td><td>works</td><td><code>captureElementImage()</code> in a paint handler, <code>remove()</code>, then the snapshot drew rgba(192,20,60,255).</td></tr>
<tr><td>Navigating checks in a hidden same-origin iframe</td><td>share the tab's history</td><td><code>history.length</code> went from 2 to 4. After the iframe was removed, one Back from the top page skipped its entries. While it was attached, its <code>history.back()</code> undid a navigation made by the top page.</td></tr>
<tr><td>The ink shader in WGSL</td><td>not verified</td><td>No WebGPU adapter. The page compares the WebGPU and WebGL pictures on a device that has one.</td></tr></tbody></table>
<p>Not verified: WebGPU on screen, the phone's Back gesture and its preview animation, cross-document navigations, and what a screen reader announces when the view changes.</p>
<p>What would verify it, on the test phone: tick "Slow", tap a card, tap inside both views while the shader runs, then go Back. Run the live checks for the WebGPU comparison.</p>
<h3>Things that bit</h3>
<ul><li>The live checks that navigate run in a hidden same-origin iframe. Its navigations are in the tab's joint history, so its <code>history.back()</code> undid a navigation the reader had made in the top page while the checks ran on load. The page's checks now wait for a tap.</li></ul>
<p><a href="https://html-in-canvas.page/nav-shader/">Open Navigations drawn by a shader</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Frames and nested canvases</title>
<link>https://html-in-canvas.page/nested-frames/</link>
<guid isPermaLink="true">https://html-in-canvas.page/nested-frames/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>nested canvas</category>
<category>iframe srcdoc</category>
<category>shadow DOM</category>
<category>foreignObject</category>
<category>paint event</category>
<description>A canvas that draws other containers: two widget canvases inside a room, an email in an &lt;iframe&gt; on a drawn phone, a custom element that draws its children through an effect, an SVG diagram with a real button in each node, and a &lt;script&gt; element that draws a wheel from its own source text.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/nested-frames/"><img src="https://html-in-canvas.page/nested-frames/social.jpg" width="1200" height="630" alt="The page &quot;Frames and nested canvases&quot;"></a></p>
<p><strong>Question:</strong> When a canvas draws a container (another drawable canvas, an iframe, a shadow tree, an SVG with foreignObject, a script element), does the content still draw, raise paint on the outer canvas when it changes, and take a tap where it was drawn?</p>
<p><strong>Short answer:</strong> Yes for all five in Chromium 157.</p>
<p>
Five ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a> in which the thing a canvas draws is itself a container with a document
or a drawing of its own: a second drawable canvas, an <code>&lt;iframe&gt;</code>, a custom element's shadow tree, an
<code>&lt;svg&gt;</code> with HTML in <code>&lt;foreignObject&gt;</code>, and the <code>&lt;script&gt;</code> element that is doing the
drawing. For each one I wanted to know whether the inner content still draws, tells the outer canvas when it changed, and takes
a tap at the place it was drawn. Each demo is one 2D canvas.
</p>
<h3>How it works</h3>
<p>In each demo the canvas draws one element whose content is produced somewhere else: by another paint handler, by another document, by a shadow tree, by SVG layout, or by the HTML parser. Four things are the same in all five:</p>
<ul>
<li><b>The container is drawn with one call.</b> <code>drawElementImage(container, x, y, width, height)</code> draws the inner canvas, the iframe, the slotted children or the SVG with everything in it.</li>
<li><b>A change inside raises <code>paint</code> outside.</b> A draw in the inner canvas, a scroll in the iframe, a typed letter in the slotted form and a new value in the SVG's output each raise <code>paint</code> on the canvas that draws the container. No demo forwards events from the inside to the outside.</li>
<li><b>Input follows the last draw.</b> A tap is tested through every transform between the outer canvas and the control. Where an effect draws a container more than once (the mirror image in the room, the tiles of the glass effect, the wedges of the wheel), the last draw decides, so each handler ends with a draw at the plain position. Where that draw must add no pixels it is made inside an empty clip.</li>
<li><b>Changes to a container are made outside the paint handler.</b> The iframe is resized and reloaded from click listeners, the SVG's output is written from a timer and the filter of the melt effect is changed in an animation frame.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, at 412 px wide with emulated touch (taps, and drags sent as touch events) and at 1100 px with a mouse. Not yet run on a phone.</p>
<ul>
<li><b>A drawable canvas can be a <code>drawable</code> child of another drawable canvas.</b> The outer canvas draws it with one <code>drawElementImage()</code> call. A draw in the inner canvas raised one <code>paint</code> event on the outer canvas, with the inner canvas in <code>changedElements</code>. A style change on an element inside the inner canvas raised one <code>paint</code> on each canvas, in that order.</li>
<li><b>Reported on Chrome 159 for Android, 2026-11-21: the room drew and the two inner canvases did not.</b> No error, lost context or script error was reported from the phone, and the cause isn't known. Headless Chromium 157 at the same pixel ratio (2.625) draws them. Since then each inner canvas is asked for its first paint, and one second after the first paint the page reads one 8 by 8 patch of a copy of the scene where the counter's card should be. If it's dark, the page switches to drawing the cards as children of the scene and sends a report. The line under the demo says which route is in use.</li>
<li><b>Input passes through both draws.</b> A button moved by the inner canvas's draw, then enlarged and sheared by the outer canvas's draw, was found by <code>elementFromPoint()</code> at the drawn place, and taps on it counted. A touch drag on the range input in the sheared lamp widget set it to 96.</li>
<li><b>An inner canvas is recorded whole.</b> A 400 px inner canvas in a 240 px outer canvas, drawn 300 px to the left, showed its pixel at 360 px. This differs from a <code>drawable</code> element nested in another <code>drawable</code> element, which <a href="https://html-in-canvas.page/keycaps/">/keycaps/</a> found is recorded clipped to the window.</li>
<li><b>A scroll inside a drawn iframe raises <code>paint</code>.</b> A touch drag of 160 px on the drawn phone screen scrolled the iframe 145 px, the page didn't scroll, and the canvas got <code>paint</code> events with the iframe in <code>changedElements</code>. The demo has no scroll or touch listener.</li>
<li><b>Links inside the iframe take taps at the drawn place</b>, with the phone upright and with the iframe drawn at 0.84 scale after the phone was turned. Resizing the iframe applied the message's media query and raised one <code>paint</code>.</li>
<li><b>The outer document sees only the iframe.</b> <code>elementFromPoint()</code> returns the <code>&lt;iframe&gt;</code>, and its <code>getBoundingClientRect()</code> is the box round the rotated drawing.</li>
<li><b>A drawable <code>&lt;div&gt;</code> round a <code>&lt;slot&gt;</code>, in a shadow tree, holds the picture of the slotted children.</b> The children need no <code>drawable</code> attribute, they're hit tested at the drawn place, and a style change on one raised <code>paint</code> with the shadow <code>&lt;div&gt;</code> in <code>changedElements</code>. A custom element with its own shadow tree, slotted in, drew and took taps too. The <code>&lt;slot&gt;</code> itself can't be drawn ("No cached paint record for element"), and a slotted child with no attribute can't be passed to <code>drawElementImage()</code>.</li>
<li><b><code>ctx.filter = 'url(#id)'</code> looks for the filter in the canvas's own tree.</b> For a canvas in a shadow root, a filter in the same shadow root applied. A filter in the document wasn't found, and the element was drawn unfiltered with no error. So a component can carry its SVG filters with it.</li>
<li><b>HTML in <code>&lt;foreignObject&gt;</code> takes input through the <code>viewBox</code>, the foreignObject's position and a sheared canvas transform together.</b> A button, a checkbox and a range (by touch drag) worked in the tilted diagram. An <code>&lt;output&gt;</code> written in the SVG raised <code>paint</code>. The foreignObject, and the button inside it, can't be the drawable element themselves ("No cached paint record for element").</li>
<li><b>A <code>&lt;script&gt;</code> element in a canvas runs, and with <code>display: block</code> it draws its source text.</b> It can be <code>contenteditable</code>, takes a tap and typed letters at its drawn place, and can pass itself to <code>drawElementImage()</code>. Changing its text doesn't run it again. A new script element put in its place runs.</li>
<li><b>An SVG element has no <code>offsetWidth</code>.</b> A draw helper that reads the size from the element passed <code>undefined</code> and drew nothing, with no error. The size of an SVG is passed in by hand.</li>
<li><b>The page drew nothing at rest</b> in the widget scene (0 scene paint events in 0.7 s after a change settled), the phone and the glass effect. The diagram, the wheel and the wave, melt and blinds effects draw every frame while they are on screen.</li>
<li><b>Not verified:</b> everything on a phone. In particular scroll momentum inside the drawn iframe, the on-screen keyboard over the name field and over the editable script, the speed of the melt effect (an SVG displacement filter on every frame), and what a screen reader reads for the inner canvases and the iframe.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/nested-frames.md">findings/nested-frames.md</a> in the repository.</p>
<p>Measured in C157 (headless Chromium 157.0.8103.78 shell) on 2026-11-21, at 412 px wide with emulated touch and at 1100 px with a mouse. Results come from the 14 live checks on the page and from <code>node tools/nested-frames/check.mjs</code>, which drives the five demos with taps, typed keys and touch drags (33 steps). Nothing here has been run on A159.</p>
<p>PLAN.md backlog group 19: 19.1 widget with its own effect inside a scene, 19.2 email preview on a drawn phone, 19.3 custom element that packages an effect, 19.4 HTML button inside an SVG diagram, 19.5 script that shows itself. Each demo is one 2D canvas (the widget demo has two small inner 2D canvases as well). No WebGL or WebGPU.</p>
<h3>A drawable canvas inside a drawable canvas</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Can a drawable canvas be a <code>drawable</code> child of a drawable canvas and be drawn by it?</td><td>measured: works</td><td>One <code>drawElementImage(inner, x, y, w, h)</code> call. The inner canvas's own fill and the element it drew are both in the picture.</td></tr>
<tr><td>Does a draw in the inner canvas raise <code>paint</code> on the outer canvas?</td><td>measured: yes, 1 event</td><td><code>changedElements</code> holds the inner canvas. The outer canvas needs no listener on the inner one.</td></tr>
<tr><td>Does a change to an element inside the inner canvas reach the outer canvas?</td><td>measured: yes</td><td>1 <code>paint</code> on the inner canvas, then 1 on the outer. The outer canvas shows the new colour.</td></tr>
<tr><td>Is a button two canvases down hit tested where it is drawn?</td><td>measured: yes</td><td>Inner draw at 20, 20, outer draw enlarged 1.25 and sheared 0.2. <code>elementFromPoint()</code> finds the button at the composed place. Taps counted (tool). Its <code>getBoundingClientRect()</code> is the drawn box.</td></tr>
<tr><td>Range input in a sheared inner canvas, touch drag</td><td>measured: works</td><td>Dragged to 90% of its drawn width: value 96.</td></tr>
<tr><td>Is an inner canvas wider than the outer canvas recorded whole?</td><td>measured: yes</td><td>400 px inner canvas in a 240 px outer canvas, drawn at x = -300: the pixel at 360 px is drawn. A direct child of a canvas is recorded whole, unlike a drawable nested in a drawable element (<code>findings/keycaps.md</code>).</td></tr>
<tr><td>The inner canvas drawn twice (upright and mirrored)</td><td>measured: the last draw takes the input</td><td>The mirror image is drawn first.</td></tr>
<tr><td><code>ctx.filter</code> on the inner canvas's draw of its element: <code>blur() brightness() saturate()</code>, and <code>url(#filter)</code> with <code>lighter</code> for a colour split</td><td>measured: works</td><td>Three draws through <code>feColorMatrix</code> filters that keep one channel each.</td></tr>
<tr><td>Paint events at rest</td><td>measured: 0 in 0.7 s</td><td>After the lamp's level settled.</td></tr></tbody></table>
<h4>Reported on A159: the inner canvases were empty</h4>
<p>reported, A159, 2026-11-21: on the owner's phone the widget demo showed the room's gradient and neither widget. <code>npm run reports -- --since 2h --list --page /nested-frames/</code> showed no report for the page, so no error, lost context or script error was raised. Not reproduced in C157 with <code>--force-device-scale-factor=2.625</code>: the room and both widgets draw and a touch tap counts.</p>
<p>Not known: whether the inner canvases got no <code>paint</code> event, drew into themselves and were then drawn empty by the outer canvas, or threw in <code>drawElementImage()</code> until the retries ran out. What the page now does (measured in C157 with <code>drawElementImage()</code> in an inner canvas replaced by a function that does nothing, as a stand-in):</p>
<table><thead><tr><th>Step</th><th>Result</th></tr></thead><tbody><tr><td>Each inner canvas is asked for its first paint with <code>requestPaint()</code></td><td>The first version waited for the browser to raise it.</td></tr>
<tr><td>One second after the scene's first paint, read one 8 by 8 patch of a <code>drawImage()</code> copy of the scene, at a point of the counter's card that holds only its pale background</td><td>Brightness 247 of 255 when the inner canvases draw, 42 in the stand-in. The limit is 140.</td></tr>
<tr><td>If dark: move the two cards out of the inner canvases to be children of the scene canvas, and let the scene run the same two effect functions inside its own transform</td><td>The widgets draw with bloom, colour split, mirror image and taps. <code>window.__gfx.report('nested-frames', …)</code> sends the paint counts.</td></tr>
<tr><td>The line under the demo</td><td>Names the route and why. A button switches route by hand.</td></tr></tbody></table>
<p>reported, 2026-11-22 08:04 UTC, the owner's phone, production with the changes above: both inner canvases draw on the nested route. His screenshot shows the lamp and the counter, mirrored, and the line "Route: nested, chosen with the button. Paint events: scene 35, lamp canvas 2, counter canvas 2. The last scene paint was raised by: #dialCanvas, #padCanvas in changedElements." No <code>nested-frames</code> report was sent in the 12 hours before, so the page's own check did not switch to the flat route: the route in the line comes from two presses of the button. So a drawable canvas nested in a drawable canvas draws on that phone. Which change made the difference is not known: the <code>requestPaint()</code> on each inner canvas, or the fix for draws with no size on high pixel ratios (PR #104), which merged in the same hour.</p>
<p>To find the cause on the phone: open the page, read the line under the room (it holds the paint counts of the three canvases at the moment of the check), and run the first four live checks, which build the same nesting on a small fixture.</p>
<h3>An iframe (<code>srcdoc</code>) as the drawable child</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Does a scroll inside the iframe raise <code>paint</code> on the canvas?</td><td>measured: yes</td><td><code>scrollTo()</code> from script: 1 event, <code>changedElements</code> holds the iframe. A touch drag of 160 px on the drawn screen scrolled the iframe 145 px and the page 0 px.</td></tr>
<tr><td>Does a link inside the iframe take a tap at the drawn place?</td><td>measured: yes</td><td>With the iframe drawn 1:1 and at 0.84 scale (phone turned). The click listener is added to <code>contentDocument</code> by the page.</td></tr>
<tr><td>What does the outer document see at that point?</td><td>measured: the <code>&lt;iframe&gt;</code></td><td><code>elementFromPoint()</code> returns the iframe. <code>getBoundingClientRect()</code> of a rotated iframe is the box round the drawing (182 by 143 for a 160 by 100 iframe turned 0.3 rad).</td></tr>
<tr><td>Does resizing the iframe apply its document's media query and raise <code>paint</code>?</td><td>measured: yes, 1 event</td><td>120 px to 200 px with a <code>min-width: 180px</code> rule.</td></tr>
<tr><td>Changing <code>srcdoc</code>, and toggling a class on the iframe's root element, from click listeners</td><td>measured: works</td><td>The picture is missing for a few frames after <code>srcdoc</code> changes. The paint loop tries again while <code>drawElementImage()</code> throws.</td></tr></tbody></table>
<h3>A custom element that draws its light-DOM children</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A <code>drawable</code> <code>&lt;div&gt;</code> in the shadow tree with a <code>&lt;slot&gt;</code> in it, as the canvas's child</td><td>measured: its picture holds the slotted children</td><td>The light-DOM children need no attribute. They are hit tested at the drawn place, and a style change on one raises <code>paint</code> with the shadow <code>&lt;div&gt;</code> in <code>changedElements</code>.</td></tr>
<tr><td>The <code>&lt;slot&gt;</code> itself with <code>drawable</code></td><td>measured: throws "No cached paint record for element"</td><td><code>display: contents</code>, no box.</td></tr>
<tr><td>A slotted child with no <code>drawable</code> attribute passed to <code>drawElementImage()</code></td><td>measured: throws "Descendants passed to DrawElementImage must have the 'drawable' attribute"</td><td>With the attribute it draws (the <code>/slot/</code> route).</td></tr>
<tr><td>A custom element with its own shadow tree, slotted into the first one</td><td>measured: draws and takes taps</td><td>The star buttons were tapped through glass, wave, melt and blinds. It is form-associated, and <code>FormData</code> held its value.</td></tr>
<tr><td><code>ctx.filter = 'url(#id)'</code> for a canvas in a shadow root</td><td>measured: resolves in that shadow root</td><td>A filter in the same shadow tree applied. A filter in the document was not found: the element drew unfiltered and nothing threw.</td></tr>
<tr><td>Changing the filter's <code>scale</code> attribute every frame (melt)</td><td>measured: the next draw uses it</td><td>Changed in <code>requestAnimationFrame</code>, not in the paint handler.</td></tr>
<tr><td>Typing in the slotted text field, submitting the slotted form</td><td>measured: works</td><td></td></tr></tbody></table>
<h3>HTML in <code>&lt;foreignObject&gt;</code></h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Button in a foreignObject, SVG drawn at 0.75 of its viewBox and sheared</td><td>measured: found by <code>elementFromPoint()</code> at the drawn place</td><td></td></tr>
<tr><td>Button, checkbox and range in the tilted diagram, by tap and touch drag</td><td>measured: work</td><td></td></tr>
<tr><td><code>&lt;output&gt;</code> in a foreignObject written by script</td><td>measured: raises <code>paint</code></td><td>Written from a timer, not inside the paint handler.</td></tr>
<tr><td>The foreignObject, or the button in it, as the <code>drawable</code> element</td><td>measured: both throw "No cached paint record for element"</td><td>The SVG root is the smallest drawable unit. ELEMENTS.md already says this for the foreignObject.</td></tr>
<tr><td><code>path.getPointAtLength()</code> for marks drawn by the canvas on the SVG's paths</td><td>measured: lines up under the same transform</td><td></td></tr></tbody></table>
<h3>A script element</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Does a <code>&lt;script&gt;</code> that is a child of a canvas run?</td><td>measured: yes</td><td>From the parser and when added by script.</td></tr>
<tr><td>With <code>display: block</code>, does it draw its text?</td><td>measured: yes</td><td>554 dark pixels in a 200 by 60 box in the check. <code>background-clip: text</code> with a gradient works on it.</td></tr>
<tr><td>Can it pass itself to <code>drawElementImage()</code>?</td><td>measured: yes</td><td><code>document.currentScript</code> at run time, <code>this</code> in the function it defines.</td></tr>
<tr><td><code>contenteditable="plaintext-only"</code> on it</td><td>measured: a tap puts the caret in it and typed letters go into its text</td><td></td></tr>
<tr><td>Does editing its text run it again?</td><td>measured: no</td><td>A new script element with the edited text, put in its place with <code>replaceWith()</code>, runs during that call.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>An SVG element has no <code>offsetWidth</code>. A helper that called <code>drawElementImage(el, x, y, el.offsetWidth, el.offsetHeight)</code> drew nothing for the SVG and threw nothing. Pass the size.</li>
<li>A classic script that declares <code>const me</code> at the top level cannot be run a second time: "Identifier 'me' has already been declared". The shown script declares nothing at the top level.</li>
<li>A syntax error in a replaced script is reported on <code>window</code> during <code>replaceWith()</code>. The page parses the text with <code>new Function()</code> first, so the error goes to the line under the demo and not to the crash reports.</li>
<li><code>kit.js</code> here is a copy of <code>/form-state/kit.js</code> with two additions: <code>put()</code> takes a size, and <code>mount()</code> takes the nodes to show as plain HTML after a lost context.</li>
<li>The scene sends <code>contextlost</code> from an inner canvas on to the page's one handler, so a loss in any of the three canvases stops all demos and shows plain HTML.</li></ul>
<h3>Not verified</h3>
<ul><li>Everything on A159. Open <code>/nested-frames/</code> on the phone and run the live checks.</li>
<li>Scroll momentum and overscroll inside the drawn iframe by a real finger. The line under the phone shows the scroll offset.</li>
<li>The on-screen keyboard over the name field in <code>&lt;effect-frame&gt;</code> and over the editable script.</li>
<li>The speed of the melt effect: an SVG turbulence and displacement filter on every frame.</li>
<li>What a screen reader reads for the inner canvases, the iframe and the foreignObject controls.</li>
<li>Whether a tap on "Run the edited script" can be lost straight after an edit. In the input tool, a tap on that button sent at once after the script's text was replaced did nothing in 3 of 6 runs. With a 0.7 s wait before the tap it worked in 4 of 4. The page had not scrolled and focus was in the script element in both cases. The cause was not found.</li>
<li>A cross-origin iframe in the phone. <code>findings/transports-2.md</code> records that it draws as transparent pixels.</li></ul>
<h3>Open ideas</h3>
<ul><li><code>&lt;effect-frame&gt;</code> with a WebGL effect through <code>lib/element-gl.js</code>, sharing the page's one context.</li>
<li>A third level: an <code>&lt;effect-frame&gt;</code> inside the email, inside the phone.</li>
<li>A node editor: dragging the diagram's nodes, with edges redrawn by the canvas.</li></ul>
<p><a href="https://html-in-canvas.page/nested-frames/">Open Frames and nested canvases</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>HTML overlays on video</title>
<link>https://html-in-canvas.page/overlay/</link>
<guid isPermaLink="true">https://html-in-canvas.page/overlay/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>MediaRecorder</category>
<category>WebCodecs</category>
<category>captureStream</category>
<category>WebRTC</category>
<description>A caption bar, a poll and a ticker in HTML over a video, in one canvas. Record it with sound, export it frame by frame with WebCodecs, or send it over WebRTC as a camera.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/overlay/"><img src="https://html-in-canvas.page/overlay/social.jpg" width="1200" height="630" alt="The page &quot;HTML overlays on video&quot;"></a></p>
<p><strong>Question:</strong> Can HTML drawn over a video in one canvas be recorded with the video's sound, exported with exact frames, and sent as a camera?</p>
<p><strong>Short answer:</strong> All three work. The export seeks the video and steps CSS animations one frame at a time.</p>
<p>
The picture below is one canvas. It draws a <code>&lt;div&gt;</code> that holds a video, a caption bar, a poll and a CSS-animated ticker.
Vote in the poll and change the name. Then record it with the video's sound, export it frame by frame, or send it over WebRTC as a camera
would be sent. The result plays under the buttons.
</p>
<h3>How it works</h3>
<ul>
<li>The canvas is a 2D canvas with a fixed 640 by 360 buffer. Every recording has that size on every screen.</li>
<li>The scene is DOM. The poll buttons take clicks inside the canvas, and the result is in the next frame of the stream.</li>
<li>Recording and sending use the canvas in real time. Export does not: it moves the video and the animations one frame at a time, so a slow device produces the same file as a fast one.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software video decoding. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: recording with sound.</strong> <code>video.captureStream()</code> gives an audio track while the element is muted, and <code>MediaRecorder</code> accepts it next to the canvas track. The file has the video frame, the HTML over it and the sound.</li>
<li><strong>Works: frame-exact export.</strong> After <code>seeked</code>, one <code>requestPaint()</code> gives a canvas with exactly the frame asked for. The frame numbers read back from an exported file were the ones asked for, and an element moved by a CSS animation was at the position for each frame's time. The cost here was about 20 to 35 ms per frame at 640 by 360.</li>
<li><strong>Works: sound in the export.</strong> <code>decodeAudioData()</code> on an <code>OfflineAudioContext</code> needs no user gesture. The slice is encoded with <code>AudioEncoder</code> (Opus) and written as a second WebM track by <code>/lib/webm-mux.js</code>.</li>
<li><strong>Works: the canvas as a camera.</strong> The stream passes through <code>RTCPeerConnection</code> and the far side receives the overlays. A camera in <code>srcObject</code> can be the video under them.</li>
<li><strong>Needed: give <code>drawElementImage()</code> a size.</strong> With only a position, the element is drawn at the size that shows it at its CSS size on screen. In a 640 px buffer shown 354 px wide, a 640 px scene is drawn 1157 buffer pixels wide and most of it is cut off. <code>drawElementImage(scene, 0, 0, canvas.width, canvas.height)</code> fills the buffer at any shown size, and it scales the hit-test region too, so the poll buttons take taps where they are drawn with no call to <code>updateElementGeometry()</code>.</li>
<li><strong>Limit: real time needs the tab.</strong> <code>paint</code> stops in a hidden tab, so a live recording or stream freezes there. The frame-by-frame export stops too and continues when the tab is shown again.</li>
<li><strong>Limit: the export seeks a file.</strong> A camera or another live stream can't be seeked, so only the live recording works for it.</li>
<li><strong>Not verified here:</strong> seek accuracy with a hardware decoder, <code>AudioEncoder</code> on Android, and how long a real phone takes per frame. The second and third live checks answer the first two on your device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-and-sound.md">findings/video-and-sound.md</a> in the repository.</p>
<h3>HTML over video: record, export, send (<code>/overlay/</code>, <code>lib/video-export.js</code>)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>canvas.captureStream()</code> plus the audio track of <code>video.captureStream()</code> into <code>MediaRecorder</code></td><td>works</td><td>The audio track is there while the element is muted. The file has the frame, the HTML and the sound.</td></tr>
<tr><td>Frame-by-frame export: seek, set each animation's <code>currentTime</code>, one <code>paint</code>, <code>new VideoFrame(canvas)</code>, <code>VideoEncoder</code></td><td>exact</td><td>Frame numbers read back from the exported file are the ones asked for. A box moved by a CSS animation is 10 px further in each frame. 21 to 26 ms per frame at 640×360 here.</td></tr>
<tr><td>Sound in the export: <code>OfflineAudioContext.decodeAudioData()</code>, <code>AudioEncoder</code> (Opus), second WebM track</td><td>works</td><td><code>lib/webm-mux.js</code> gained <code>addAudio()</code>. No user gesture is needed.</td></tr>
<tr><td>Canvas stream through <code>RTCPeerConnection</code></td><td>works</td><td>640×360 at 30 frames a second with the overlays in it.</td></tr>
<tr><td>Buttons in a scene drawn into a fixed 640×360 buffer shown at another size</td><td>work</td><td><code>drawElementImage(el, 0, 0, canvas.width, canvas.height)</code> scales the picture and the hit-test region together.</td></tr>
<tr><td><code>drawElementImage(el, 0, 0)</code> on a buffer that is not the shown size</td><td>overflows</td><td>With no size, the element is drawn at the size that shows it at its CSS size on screen, whatever the buffer size.</td></tr>
<tr><td>Export of a camera or other live stream</td><td>not possible</td><td>It cannot be seeked. Only the real-time recording applies.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/overlay/">Open HTML overlays on video</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Paint clocks</title>
<link>https://html-in-canvas.page/paint-clocks/</link>
<guid isPermaLink="true">https://html-in-canvas.page/paint-clocks/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>paint event</category>
<category>drawElementImage</category>
<category>video</category>
<category>animation</category>
<description>A loading effect that runs while a &lt;progress&gt; bar has no value, a card that beats with the caret, a scene placed from a video's currentTime, and a flag that moves one step for each frame of an animated GIF. The element's own repaints are the only clock: no requestAnimationFrame() and no timer.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/paint-clocks/"><img src="https://html-in-canvas.page/paint-clocks/social.jpg" width="1200" height="630" alt="The page &quot;Paint clocks&quot;"></a></p>
<p><strong>Question:</strong> Can the repaints of an element (an indeterminate progress bar, a caret, a video, an animated image) be the only clock for a canvas effect, with no requestAnimationFrame(), timer or requestPaint() loop?</p>
<p><strong>Short answer:</strong> Yes for all four. Measured paint rates in Chromium 157: 60 per second from a CSS-animated bar, 8 from the browser's own bar, 2 from a caret, 30 from a 30 fps video, and the frame rate of the GIF. Each effect stops when its element stops. Drawing an element at a new place raises a second paint event, so a handler has to read changedElements to tell the clock's events from those.</p>
<p>
Four ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>. Some elements repaint by themselves: an indeterminate progress bar, a
blinking caret, a playing video, an animated image. Each repaint raises <code>paint</code> on the canvas that holds the element. On this
page that event is the only clock. No demo calls <code>requestAnimationFrame()</code>, starts a timer or asks for paints in a loop, so
each effect runs at the rate of its element and stops when the element stops. The line under each canvas counts the paint events.
</p>
<h3>How it works</h3>
<p>A drawable canvas gets a <code>paint</code> event when the picture of one of its <code>drawable</code> descendants changes. An element that animates by itself therefore raises a steady run of <code>paint</code> events, at its own rate, for as long as it animates. Each demo has one paint handler and nothing else that runs over time:</p>
<ul>
<li><b>Where the time comes from.</b> The loading effect reads <code>performance.now()</code> inside the handler, so it moves at the right speed at any paint rate. The film reads <code>video.currentTime</code>. The flag and the heartbeat count paint events, so their speed is the element's rate.</li>
<li><b>Stopping.</b> There is nothing to stop. When the bar gets a value, the field loses focus, the video pauses or the image is removed, the element stops repainting and the handler isn't called again.</li>
<li><b>The clock doesn't have to be drawn.</b> A <code>drawable</code> element raises <code>paint</code> whether or not the handler draws it. It does have to be painted by the browser at least once: an image that has <code>opacity: 0</code> from the start raised no events, and an element with <code>visibility: hidden</code> has no picture. An image that was already running kept raising events after it was given <code>opacity: 0</code>.</li>
<li><b>One exception.</b> An element has no picture until the browser has painted it once. If a draw fails for that reason, the handler asks for one more paint, at most 30 times, when the page starts.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.</p>
<ul>
<li><b>All four elements work as the only clock.</b> Measured paint rates: 60 per second from a bar with a CSS animation, 8 from the browser's own indeterminate bar, 2 from a caret (one event each 500 ms), 30 from a 30 frames per second video, and 12.5 and 4.2 from GIFs with 80 ms and 240 ms frames. A canvas with no changing element got 0 in a second.</li>
<li><b>Each effect stops with its element.</b> A bar that gets a value, a field that loses focus, a paused video and a removed image raised no further <code>paint</code>. The page cancels nothing.</li>
<li><b>Drawing an element at a new place raises a second <code>paint</code> one frame later.</b> Its <code>changedElements</code> names the element that was moved, not the clock. Before this was handled, the flag ran at twice the rate of its image and the card beat twice for each blink. Each handler now counts a tick only when <code>changedElements</code> holds the clock, and redraws the same frame for any other event.</li>
<li><b>The clock has to stay still to be told apart.</b> When the video was drawn with a small tilt that changed each frame, 42 events a second named the video for 30 frames of film. Drawn at a fixed place it gives 30. The caret's field is a separate <code>drawable</code> element from the card that beats, for the same reason.</li>
<li><b>A clock doesn't have to be drawn.</b> An image that the handler never draws raised 12.0 events a second. An image that had <code>opacity: 0</code> from the start raised none, and an element with <code>visibility: hidden</code> has no picture. An image that was already running kept raising about 12 events a second after it was given <code>opacity: 0</code>.</li>
<li><b>A video raises one <code>paint</code> for each frame it shows:</b> 46 paint events for 45 frames reported by <code>requestVideoFrameCallback()</code> in 1.5 s. A seek while paused raises <code>paint</code> for the new frame, so the scene follows the slider with no <code>seeked</code> listener.</li>
<li><b>A clock with two paint events a second gives an effect two states.</b> Nothing raises <code>paint</code> between two blinks of the caret, so the heartbeat can't ease from one state to the other without a second clock.</li>
<li><b>Counting events and reading the time give different effects.</b> The flag counts, so the file's frame delay sets its speed. The loading effect reads <code>performance.now()</code>, so its speed is the same at 8 and at 60 events a second and only its smoothness changes.</li>
<li><b>Not verified:</b> everything on a phone. In particular the caret's blink interval on Android (printed under the demo), whether the on-screen keyboard changes it, whether Chrome on Android pauses an animated image or a video's paint events when the canvas scrolls off screen, and the paint rate of a video decoded in hardware.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/paint-clocks.md">findings/paint-clocks.md</a> in the repository.</p>
<p>Four ideas from the element catalogue (ideas 18.4 to 18.7 of the backlog in PLAN.md). Measured in headless Chromium 157 (C157) on 2026-11-21 at 412 px wide. The page's seven live checks pass there, and <code>node tools/paint-clocks/check.mjs</code> drives the four demos with real input (20 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: can the repaints of an element be the only clock for a canvas effect, with no <code>requestAnimationFrame()</code>, no timer and no <code>requestPaint()</code> loop?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>A canvas whose elements do not change</td><td>0 paint events in 1 s</td><td>The base line.</td></tr>
<tr><td><code>&lt;progress&gt;</code> with no value and a CSS animation on its background</td><td>60.0 paint events per second</td><td>Each animation frame repaints the element. The loading effect runs from it.</td></tr>
<tr><td>The browser's own indeterminate <code>&lt;progress&gt;</code></td><td>8.0 per second</td><td>The built-in animation repaints at that rate in C157.</td></tr>
<tr><td>The same bars after <code>value</code> is set</td><td>0.0</td><td><code>:indeterminate</code> no longer matches, the animation ends, and <code>paint</code> stops. The page cancels nothing.</td></tr>
<tr><td>A focused <code>&lt;input&gt;</code></td><td>2 per second, 500 ms apart</td><td>One event each time the caret goes on or off. A typed letter raises one as well (5 in a second while typing three letters). After blur: none.</td></tr>
<tr><td>A playing 30 fps <code>&lt;video&gt;</code></td><td>30.7 per second</td><td>46 paint events for 45 frames from <code>requestVideoFrameCallback()</code> in 1.5 s. Paused: 0.</td></tr>
<tr><td>Seek of a paused video</td><td>one <code>paint</code> for the new frame</td><td>The scene, placed from <code>currentTime</code>, moved to 7.01 s after a seek to 70% of 10 s with no <code>seeked</code> listener.</td></tr>
<tr><td>Animated GIF, 80 ms and 240 ms per frame</td><td>12.7 and 4.2 per second</td><td>The file's frame rate. A handler that counts events runs at the speed stored in the file.</td></tr>
<tr><td>The image is never drawn by the handler</td><td>12.0 per second</td><td>A <code>drawable</code> element raises <code>paint</code> whether or not <code>drawElementImage()</code> is called for it.</td></tr>
<tr><td>The image is removed</td><td>0.0</td><td></td></tr>
<tr><td><code>opacity: 0</code> on the image from the start</td><td>0.0</td><td>It was never painted, so it never started.</td></tr>
<tr><td><code>opacity: 0</code> given to a running image</td><td>12.5 per second</td><td>The events continue. An earlier version of this page claimed they stop: that was the page's own text, not a count.</td></tr>
<tr><td><code>visibility: hidden</code> on the image</td><td>no picture</td><td><code>drawElementImage()</code> throws "No cached paint record for element".</td></tr>
<tr><td>Drawing an element at a different place than in the last paint</td><td>a second paint event one frame later</td><td><code>changedElements</code> names the element that was moved, not the clock. Live check: 10 events named a 240 ms image and 10 more named only the div drawn 5 px further along each time.</td></tr>
<tr><td>The effect of that on a handler that counts paint events</td><td>twice the rate</td><td>Before it was handled the flag showed 26 events a second for a 12.5 per second image, and the card beat twice per blink, 17 ms apart.</td></tr>
<tr><td>The fix</td><td><code>changedElements</code> and a clock that stays still</td><td>A tick is counted only when <code>changedElements</code> holds the clock element. Any other event redraws the same frame. The clock must not be moved by the drawing: a video drawn with a tilt that changed each frame gave 42 events a second that named the video, and 30 when drawn at a fixed place. The caret's field is its own <code>drawable</code> element, separate from the card that beats.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops all four and shows the elements as plain HTML (4 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The doubled rate was first seen as "paint events in the last second: 26" under a 12.5 per second image. A fixture that drew the image alone showed 12.5, so the cause was the other draws.</li>
<li><code>python3 -m http.server</code> has no range requests, so the video is not seekable from it (<code>seekable.length</code> 0) and a seek goes to 0. <code>tools/paint-clocks/check.mjs</code> serves <code>public/</code> itself with ranges.</li>
<li>A demo that stops gets no paint event in which to write "stopped". The status line is written in the last paint event the element raises (the bar's value change, the blur, the removal), and for the video in a <code>pause</code> listener.</li>
<li>A switch between the CSS-animated bar and the browser's own bar inside the demo gave 27 to 61 events a second that named the bar, not 8. A fixture with the browser's bar beside a moving element gave 8. The cause was not found, the switch was removed, and the rate of the browser's bar is measured by a live check.</li>
<li>An element has no picture until the browser has painted it once. With no frame loop a failed first draw would leave the canvas empty, so the handler asks for one more paint after a failed draw, at most 30 times.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: all four demos by touch.</li>
<li>The caret's blink interval on Android, and whether the on-screen keyboard changes it. The line under the heartbeat prints the interval.</li>
<li>Whether Chrome on Android pauses an animated image, a CSS animation or a video's paint events while the canvas is scrolled off screen.</li>
<li>The paint rate of a video decoded in hardware.</li>
<li>Why the browser's own bar raised more than 8 events a second inside the loading demo (see "Things that bit").</li>
<li>Whether the second paint event after a moved draw is intended. It needs a reduction outside this page.</li></ul>
<p><a href="https://html-in-canvas.page/paint-clocks/">Open Paint clocks</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Paint event inspector</title>
<link>https://html-in-canvas.page/paint-inspector/</link>
<guid isPermaLink="true">https://html-in-canvas.page/paint-inspector/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>paint</category>
<category>changedElements</category>
<category>requestPaint</category>
<category>video</category>
<category>marquee</category>
<description>Eleven elements drawn by one canvas: a text field, a clock, CSS animations, a video, a marquee, a progress bar. Each flashes when a paint event names it and shows a count, a rate and a strip of its recent events. Three of the animated ones never fire.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/paint-inspector/"><img src="https://html-in-canvas.page/paint-inspector/social.jpg" width="1200" height="630" alt="The page &quot;Paint event inspector&quot;"></a></p>
<p><strong>Question:</strong> Which changes to a drawn element raise a paint event that names it, and how often?</p>
<p><strong>Short answer:</strong> In Chromium 157 a background animation, a marquee and an animated descendant are named on every frame, a playing 30 fps video about 30 times a second, an indeterminate progress bar 8 times a second and a caret 2 times a second. A transform or opacity animation on the drawable element itself is named once, for its first picture, and never again. The same holds for an element that doesn't change.</p>
<p>
One canvas draws eleven elements. Each time the canvas gets a <code>paint</code> event, the elements named in
<code>event.changedElements</code> flash. The label on each element is its count and its rate over the last second, and the strip
under it is its last four seconds. Type in the field, press the button, and start the video to see which changes raise an event.
</p>
<h3>How it works</h3>
<ul>
<li>The inspector is one <code>paint</code> listener on the canvas. For every element in <code>event.changedElements</code> it adds one to a count and stores the time.</li>
<li>The canvas is redrawn on every animation frame while it is on screen, because the strips move. Each frame draws all eleven elements with <code>drawElementImage()</code> and then the overlay. Drawing doesn't raise a paint event.</li>
<li>The colour is the rate over the last second: grey for none, green for up to 3, amber for up to 20, red above that.</li>
<li>"transform on the element" and "opacity on the element" animate the drawable element itself. The picture of an element is its own box before its transform and opacity are applied, so the animation isn't in the picture: the two tiles don't move or fade here, and no event names them.</li>
<li>The video loads when you press "Play the video" or tap it, so that the page doesn't take a video decoder on load.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless with software rendering, on 2026-11-21. The rates are from a 60 Hz frame clock. The rows above say what your browser does.</p>
<ul>
<li><strong>Every frame:</strong> a <code>background-color</code> animation, a <code>&lt;marquee&gt;</code>, and a transform animation on a descendant of the drawable element (120 events in 2 s each). The event for the descendant names its drawable ancestor.</li>
<li><strong>Per video frame:</strong> a playing 30 fps clip was named 59 times in 2 s.</li>
<li><strong>8 times a second:</strong> a <code>&lt;progress&gt;</code> with no value. <strong>2 times a second:</strong> the caret of a focused text field.</li>
<li><strong>Never after the first picture:</strong> a transform or opacity animation on the drawable element itself, and an element that doesn't change. Each is named once, when its first picture is ready.</li>
<li><strong>A listener added late misses that first mention.</strong> With the listener added 300 ms after the element was put in the canvas, the event raised by <code>requestPaint()</code> listed no elements. A page can't use <code>changedElements</code> alone to decide what to draw first.</li>
<li><strong>Paint events don't wait for a draw.</strong> With a listener that draws nothing, the events kept arriving at the same rate.</li>
<li><strong>Cost to keep in mind:</strong> one animated element raises a paint event on every frame for the whole canvas. A page that uploads textures in its paint handler should upload only the elements in <code>changedElements</code>.</li>
<li><strong>Not verified here:</strong> the rates on a phone, where the frame clock can be 90 or 120 Hz and video is decoded by hardware. Open this page on the phone and read the labels. Hover doesn't exist on a touch screen, so the button is named only when pressed or focused.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/paint-inspector.md">findings/paint-inspector.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (C157) with software rendering on 2026-11-21, 60 Hz frame clock. Counts are events whose <code>changedElements</code> held the element.</p>
<table><thead><tr><th>Change</th><th>Events</th><th>Detail</th></tr></thead><tbody><tr><td><code>background-color</code> animation on a drawable element</td><td>every frame</td><td>30 in 0.5 s.</td></tr>
<tr><td>Transform animation on a descendant of a drawable element</td><td>every frame</td><td>30 in 0.5 s. The event names the drawable ancestor.</td></tr>
<tr><td><code>&lt;marquee&gt;</code></td><td>every frame</td><td>30 in 0.5 s.</td></tr>
<tr><td>Playing 30 fps video</td><td>one per video frame</td><td>30 events in 1 s, and <code>getVideoPlaybackQuality()</code> reported 30 frames.</td></tr>
<tr><td><code>&lt;progress&gt;</code> with no value</td><td>8 a second</td><td></td></tr>
<tr><td>Caret of a focused text field</td><td>2 a second</td><td>4 events in 1.6 s including the focus ring.</td></tr>
<tr><td>Text set by script</td><td>1 per change</td><td>The neighbour was not named.</td></tr>
<tr><td>Transform animation on the drawable element itself</td><td>none</td><td>The picture is the element before its own transform. 0 paint events arrived at all.</td></tr>
<tr><td>Opacity animation on the drawable element itself</td><td>none</td><td>Same.</td></tr>
<tr><td>An element that does not change</td><td>named once, for its first picture</td><td>Not named again.</td></tr>
<tr><td>A listener added 300 ms after the element was put in the canvas</td><td>first event lists no elements</td><td><code>requestPaint()</code> raised the event. The first mention of the element was lost.</td></tr>
<tr><td>A paint listener that draws nothing</td><td>events keep arriving</td><td>30 in 0.5 s.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A <code>&lt;progress&gt;</code> styled as a 60 px tall tile (the tile class sets a background, padding and <code>overflow: hidden</code>) drew as a flat grey box with no animation, and its count stayed at 2. The page now puts an unstyled <code>&lt;progress&gt;</code> inside a drawable <code>&lt;div&gt;</code>.</li>
<li>After the checks finished, every tile was named once more at the same moment. The cause was not looked for. It reads as a repaint of the whole canvas content.</li></ul>
<h3>Not verified</h3>
<ul><li>The rates on a phone (90 or 120 Hz frame clock, hardware video decoding). Open the page on the phone and read the labels.</li>
<li>Hover: a touch screen has none, so the button tile is named on press and focus only.</li></ul>
<p><a href="https://html-in-canvas.page/paint-inspector/">Open Paint event inspector</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Partial updates and moved elements drawn by a canvas</title>
<link>https://html-in-canvas.page/patch/</link>
<guid isPermaLink="true">https://html-in-canvas.page/patch/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>&lt;template for&gt;</category>
<category>streamAppendHTMLUnsafe</category>
<category>moveBefore</category>
<category>changedElements</category>
<description>Streamed &lt;template for&gt; patches fill named ranges in tiles that a canvas draws, out of order, and moveBefore() reorders the tiles while an input keeps its focus. The canvas shows where each patch lands and flies each tile to its new place.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/patch/"><img src="https://html-in-canvas.page/patch/social.jpg" width="1200" height="630" alt="The page &quot;Partial updates and moved elements drawn by a canvas&quot;"></a></p>
<p><strong>Question:</strong> What does a canvas see when declarative partial updates (<code>&lt;template for&gt;</code> and processing-instruction ranges) change its children, when a patch adds a new drawable element, and when <code>moveBefore()</code> moves one?</p>
<p><strong>Short answer:</strong> Each chunk of a patch raises a paint event and changedElements names the patched tile only. A drawable element that arrives in a patch can be drawn at the next paint. moveBefore() keeps focus, animation time and the tile's texture. Only the Unsafe streaming methods apply patches.</p>
<p>
The tiles below are children of a canvas. Four of them hold a named range, <code>&lt;?start name="orders"?&gt;</code> to <code>&lt;?end?&gt;</code>. A stream of
<code>&lt;template for="orders"&gt;</code> elements replaces each range, in any order, with no script touching the tiles. The canvas draws every tile as its own texture, so it can
show which tile a patch is landing in, and it can fly a tile from its old place to its new one when <code>moveBefore()</code> reorders the list.
</p>
<h3>How it works</h3>
<p>Each tile is a <code>drawable</code> element with its own texture. The patch buttons write <code>&lt;template for&gt;</code> elements into the document with <code>streamAppendHTMLUnsafe()</code>, 14 characters at a time. The browser puts each template's content into the range of the same name. A <code>MutationObserver</code> records which tile changed and when; the <code>paint</code> event's <code>changedElements</code> says which textures to upload again. A shuffle records where each tile is drawn, reorders the elements, and the canvas draws each quad on a path from the old place to the tile's new layout box for 600 ms.</p>
<h3>Findings</h3>
<ul>
<li>A <code>&lt;template for="name"&gt;</code> written through <code>streamAppendHTMLUnsafe()</code> replaces the range of that name, including a range that was in the document before the stream
started. The content appears in the range while the template is still open, so text streams into the middle of the page (Chromium 157).</li>
<li>The sanitising methods (<code>streamAppendHTML()</code>, <code>appendHTML()</code>) remove processing instructions and patch templates, so nothing is patched. The one-shot methods
(<code>appendHTMLUnsafe()</code>, <code>insertAdjacentHTML()</code>) insert the template and leave it unapplied. <code>innerHTML</code> applies a patch only to a range in the same string.</li>
<li>When a template closes, its <code>start</code> and <code>end</code> instructions are removed. A patch that should be repeatable has to write them again inside its own content.</li>
<li>Each chunk of a patch raises one <code>paint</code> event with no call to <code>requestPaint()</code>, and <code>changedElements</code> names the tile that holds the range, not the whole document.
Only that tile is uploaded again.</li>
<li>A <code>drawable</code> element that arrives inside a patch has a picture at the next <code>paint</code> event and can be uploaded then. It needs no registration.</li>
<li><code>moveBefore()</code> on a tile keeps the focus and the selection of an input inside it and keeps its CSS animation running. The tile's texture is still valid after the move, so the canvas
only changes where it draws it. <code>insertBefore()</code> on the same tile drops the focus and restarts the animation.</li>
<li>Moving a drawable element to a different canvas with <code>moveBefore()</code> also keeps focus; the new canvas gets a <code>paint</code> event and can draw it.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/patch.md">findings/patch.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell). Not yet run on the test phone.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>&lt;template for="name"&gt;</code> and <code>&lt;?start name?&gt;</code> … <code>&lt;?end?&gt;</code> ranges in a canvas child</td><td>work</td><td>In the document's own parse, in <code>document.write()</code>, and through the <code>stream…HTMLUnsafe()</code> methods. A streamed template patches a range that was in the document before the stream started.</td></tr>
<tr><td>Which methods apply a patch</td><td>only the streaming <code>Unsafe</code> ones</td><td><code>streamAppendHTML()</code> and <code>appendHTML()</code> sanitise: processing instructions and patch templates are dropped. <code>appendHTMLUnsafe()</code> and <code>insertAdjacentHTML()</code> insert the template element and leave it unapplied. <code>innerHTML</code> applies a patch to a range in the same string only.</td></tr>
<tr><td>Content while the template is open</td><td>streams into the range</td><td>The range shows the part of the template that has arrived.</td></tr>
<tr><td>After the template closes</td><td>the <code>start</code> and <code>end</code> instructions are removed</td><td>A <code>&lt;?marker?&gt;</code> is consumed too. A repeatable patch writes new instructions inside its own content.</td></tr>
<tr><td>Paint events</td><td>one per chunk</td><td>No <code>requestPaint()</code>. <code>changedElements</code> names the nearest drawable element around the range, so with one drawable tile per range only that tile is uploaded.</td></tr>
<tr><td>A new <code>drawable</code> element inside a patch</td><td>drawn at the next paint</td><td>It has a picture when the <code>paint</code> event that follows its insertion runs.</td></tr>
<tr><td><code>moveBefore()</code> on a drawable tile</td><td>state kept</td><td>Focus and selection of an input inside it, and the time of a CSS animation, are kept. The texture uploaded before the move is still the tile's picture. <code>insertBefore()</code> drops the focus and restarts the animation.</td></tr>
<tr><td><code>moveBefore()</code> to a child of another canvas</td><td>works</td><td>Focus is kept and the second canvas gets <code>paint</code> events.</td></tr></tbody></table>
<h3>Not verified</h3>
<ul><li>Chrome 159 on the test phone: whether it has <code>&lt;template for&gt;</code> and the <code>Unsafe</code> streaming methods. The page's first live check reports it.</li>
<li>Chromium 153 has neither feature; the patch buttons are disabled there.</li></ul>
<p><a href="https://html-in-canvas.page/patch/">Open Partial updates and moved elements drawn by a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Five follow-ups to the Chrome APIs plan</title>
<link>https://html-in-canvas.page/plan-followups/</link>
<guid isPermaLink="true">https://html-in-canvas.page/plan-followups/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Summarizer</category>
<category>multicol</category>
<category>TextMetrics</category>
<category>RGBA16F</category>
<category>custom-ident</category>
<description>One stage, five small experiments: tiles that swap to a one-sentence stand-in when they're too small to read, the columns of a multi-column element turned like pages, canvas text selection rectangles against DOM range rectangles, a float WebGL buffer with a bloom pass, and a shader effect picked by a custom property.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/plan-followups/"><img src="https://html-in-canvas.page/plan-followups/social.jpg" width="1200" height="630" alt="The page &quot;Five follow-ups to the Chrome APIs plan&quot;"></a></p>
<p><strong>Question:</strong> What do five open ideas from the Chrome APIs plan do when built: semantic zoom, column pages, TextMetrics selection rectangles, a float WebGL buffer, and an effect chosen in CSS?</p>
<p><strong>Short answer:</strong> All five draw. A multi-column element is one picture that holds every column. Scroll markers of a column scroller aren't in the picture. TextMetrics.getSelectionRects() needs Chrome 160 or the experimental flag. A drawable WebGL canvas accepts an RGBA16F drawing buffer. A registered custom-ident changes at the halfway point of a transition.</p>
<p>
Five small experiments that the Chrome APIs plan left open, on one stage. Pick one. <b>Semantic zoom</b> swaps a tile that is too small to read for a one-sentence stand-in.
<b>Column pages</b> turns the columns of a multi-column element like pages. <b>Text rectangles</b> compares the selection rectangles of canvas text with those of a DOM range.
<b>Float buffer</b> draws a panel into a 16-bit float WebGL buffer with a bloom pass. <b>Effect from CSS</b> picks the shader effect of each card with a custom property.
The stage starts on a 2D canvas. The WebGL context is made when one of the last three is first chosen.
</p>
<h3>How it works</h3>
<p><b>Semantic zoom.</b> Six tiles and six stand-ins are children of a 2D canvas. The canvas draws each tile at its place in a 3 by 2 grid, scaled by the zoom. Body text is 14 pixels, so under a zoom of about 0.6 it is
below 8.5 pixels on screen. Between 0.5 and 0.72 the tile fades out and its stand-in fades in at the same rectangle. The stand-in holds the first sentence of the tile until "Use the Summarizer API" is pressed,
which asks <code>Summarizer</code> for a headline of each tile. Both are elements, so a tap on either one reaches a click handler at any zoom.</p>
<p><b>Column pages.</b> The article has <code>columns: 5</code>, a fixed height and no gap, and is 1,250 pixels wide. Its picture is uploaded once as a texture. A page is one fifth of the texture. During a turn the shader maps
the top page onto a cylinder that rolls from right to left and shows the back of the paper where it has come over. After each draw <code>updateElementGeometry()</code> places the element so that the shown page lines up with its picture.</p>
<p><b>Text rectangles.</b> The top line is a DOM element drawn with <code>drawElementImage()</code>, and the blue boxes are <code>Range.getClientRects()</code> for the chosen characters. The bottom line is the same string drawn with
<code>fillText()</code> in the same font, and the orange boxes are <code>TextMetrics.getSelectionRects()</code>, which is in Chrome 160 and behind the experimental features flag before it. The status line gives both lists and the largest difference.</p>
<p><b>Float buffer.</b> <code>texElementSubImage2D()</code> gives WebGL an 8-bit picture, so no value above 1.0 arrives. The shader multiplies the badge, the button and the full-white pixels of the strip, and draws into an
<code>RGBA16F</code> texture. A bright pass keeps what is above 1.0, four blur passes at a quarter of the size spread it, and the composite adds it back. The canvas's own buffer is asked to be <code>RGBA16F</code> with
<code>drawingBufferStorage()</code>, in Display P3, with <code>drawingBufferToneMapping({ mode: 'extended' })</code> where that exists. The page asks for the float buffer at the start only on a screen that matches <code>(dynamic-range: high)</code>.
If the stage is empty with the float buffer, choose the 8-bit one: the bloom is the same and nothing passes white.</p>
<p><b>Effect from CSS.</b> <code>--fx</code> is registered as a <code>&lt;custom-ident&gt;</code>. Once a frame the page reads it from each card with <code>getComputedStyle()</code> and looks the name up in a table of effect numbers, next to the
number and colour uniforms that <code>lib/css-uniforms.js</code> reads. The binding is in this page's own code. <code>lib/shader-fx.js</code> wasn't changed, because it's shared by other pages.</p>
<h3>Findings</h3>
<ul>
<li>Measured in Chromium 157 (headless, software rendering) on 2026-11-21. The live checks above give the answers for the browser you are using.</li>
<li>A drawn element keeps its click target at any scale in a 2D canvas. A 200 by 100 element drawn at 60 by 30 is clicked inside the small rectangle and not where its full size would be.</li>
<li>An element that isn't drawn in a paint keeps the click target of its last draw. When the stage changed experiment, the tiles of the first one were still clicked through the text of the third. The page draws each unused element outside the canvas with an alpha of 0, and on the WebGL canvas moves it with <code>updateElementGeometry()</code>.</li>
<li>An element with <code>columns: 5</code> and a fixed height is one picture with all five columns, 2,500 by 660 pixels at a scale of 2. No scroll container is needed to get the columns of a text as separate pages.</li>
<li>The scroll markers of a multi-column scroller (<code>::column::scroll-marker</code> with <code>scroll-marker-group: after</code>) aren't in the picture of the drawn scroller: the picture is the size of the element and no marker pixel is in the canvas. Setting <code>scrollLeft</code> on the drawn scroller changes its picture to the next column.</li>
<li><code>TextMetrics.getSelectionRects()</code> is absent without the experimental features flag. With the flag, for 20 pixel serif text, its rectangle and the one from <code>Range.getClientRects()</code> start within 0.01 pixels of each other, differ by 0.03 pixels in width and are both 22 pixels tall. For a selection across Latin and Hebrew text in the demo both give three rectangles of the same widths, and the largest difference at an edge is 0.43 pixels.</li>
<li><code>drawingBufferStorage(gl.RGBA16F, …)</code> is accepted on a drawable WebGL canvas, <code>texElementSubImage2D()</code> still uploads into the context, and a white box multiplied by 4 reads back as 4.00 from the float scene texture and from the drawing buffer. <code>drawingBufferToneMapping()</code> exists only with the experimental features flag.</li>
<li>The test browser, which composites in software, shows nothing for a WebGL canvas with an <code>RGBA16F</code> drawing buffer: the canvas is empty on screen and the console reports an invalid <code>readPixels</code> format for each frame, although the buffer holds the picture. So the page asks for the float buffer at the start only where <code>(dynamic-range: high)</code> matches, and has a control for both.</li>
<li>A registered <code>&lt;custom-ident&gt;</code> reads back from <code>getComputedStyle()</code> as the name. In a 1 second linear transition it read <code>none</code> at 0.25 s and <code>wave</code> at 0.75 s, while a registered number read 0.25 and 0.75.</li>
<li>Seen on my phone (Chrome 159, Android, experimental features flag on) on 2026-11-22: the <code>RGBA16F</code> drawing buffer is shown, with tone mapping <code>extended</code>, and the raised parts are much brighter than white. At a headroom of 4.0 and a bloom of 1.0 the labels were hard to read, so the page now starts at 2.5 and 0.4. With the 8-bit buffer every raised pixel was cut off at white and the labels were lost. The composite now scales such a pixel down with its colour kept. On the float buffer the labels of the button and the badge and the word in the strip were then reported readable, the word "very clear".</li>
<li>Not verified: what <code>Summarizer</code> returns. The test browser has no HDR output and reports the model as "downloadable".</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/plan-followups.md">findings/plan-followups.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, software rendering), 2026-11-21, at 412 pixels wide and a scale of 2, once with no flags and once with <code>--enable-experimental-web-platform-features</code>. Not yet run on the test phone.</p>
<p>One page builds the five items of backlog group 26 on one stage. Two canvases are stacked: a 2D canvas for semantic zoom and text rectangles, and a WebGL canvas (one <code>ElementGL</code>, made the first time it is needed) for column pages, the float buffer and the effect from CSS. <code>public/plan-followups/stage.js</code> holds the fragment shader, the bloom chain and the float drawing buffer call.</p>
<table><thead><tr><th>Item</th><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>26.1</td><td>A tile drawn at 0.3 of its size: where is it clicked</td><td>at the small rectangle (measured)</td><td>A 200 by 100 element drawn at 100, 40, 60, 30. <code>elementFromPoint()</code> gives the button inside that rectangle and not at 40, 20.</td></tr>
<tr><td>26.1</td><td>Swapping a tile for a stand-in as the zoom falls</td><td>works (measured by screenshot)</td><td>Body text is 14 px. Between a zoom of 0.72 and 0.5 the tile fades out and a second element with one sentence in 23 px bold fades in at the same rectangle. Both have the same click handler.</td></tr>
<tr><td>26.1</td><td><code>Summarizer</code></td><td>present, <code>availability()</code> is "downloadable" (measured)</td><td>The button calls <code>Summarizer.create({ type: 'headline', format: 'plain-text', length: 'short' })</code>. What it returns is not verified. Until then the stand-in is the first sentence of the tile.</td></tr>
<tr><td>26.1, all</td><td>An element that a paint does not draw</td><td>keeps the click target of its last draw (measured)</td><td>After changing from semantic zoom to text rectangles, a point in the lower line of text still answered with a stand-in tile. Fixed by drawing each unused element at -4000, -4000 with <code>globalAlpha</code> 0, and on the WebGL canvas by <code>updateElementGeometry()</code> with a translation out of the canvas.</td></tr>
<tr><td>26.2</td><td>An element with <code>columns: 5</code>, a fixed height and <code>column-fill: auto</code></td><td>one picture with all five columns (measured)</td><td>Five coloured blocks with <code>break-after: column</code> read red, green, blue, yellow, magenta at the five column centres. The demo's article is 1,250 by 330 CSS pixels, a texture of 2,500 by 660 at a scale of 2.</td></tr>
<tr><td>26.2</td><td>Page turn</td><td>works (measured by screenshot)</td><td>Two quads from the one texture. The top one maps the page onto a cylinder of radius 0.07 page widths that moves from right to left, with the back of the paper drawn mirrored and lightened. The texture is uploaded when the element paints, not on each frame of the turn.</td></tr>
<tr><td>26.2</td><td>Text and link of the shown page</td><td>clickable at the picture (measured)</td><td><code>updateElementGeometry()</code> with a translation of the page's place minus <code>page * 250</code>. The transform is in CSS pixels. The link on page 2 answers <code>elementFromPoint()</code> at its drawn place.</td></tr>
<tr><td>26.2</td><td><code>scrollLeft</code> on a drawn multi-column scroller</td><td>changes the picture (measured)</td><td>Red before, green after a scroll of 200.</td></tr>
<tr><td>26.2</td><td><code>::column::scroll-marker</code> of a drawn scroller with <code>scroll-marker-group: after</code></td><td>not in the picture (measured)</td><td>The picture is 200 by 60, the size of the element. No marker pixel is found anywhere in a 200 by 100 canvas. <code>CSS.supports('selector(::column)')</code> is true. So the <code>::column</code> route gives a canvas nothing that the plain multi-column element does not: the fragments are not separate pictures.</td></tr>
<tr><td>26.3</td><td><code>TextMetrics.getSelectionRects()</code> with no flag</td><td>absent (measured)</td><td>The page shows the range rectangles and says so. The live check is expected to fail there.</td></tr>
<tr><td>26.3</td><td>With the experimental features flag, characters 6 to 12 of "Hello canvas text" at 20 px serif</td><td>Range 49.42 + 54.44, TextMetrics 49.43 + 54.41, both 22.0 tall (measured)</td><td></td></tr>
<tr><td>26.3</td><td>A selection across Latin and Hebrew text, characters 3 to 22 of the demo line at 24 px serif</td><td>three rectangles from each, same widths (measured)</td><td>Range 37.1 + 82.2, 119.4 + 57.9, 177.3 + 49.4. TextMetrics 37.6 + 82.2, 119.8 + 57.9, 177.6 + 49.4. Largest difference at an edge 0.43 px. The offset of about 0.4 px is constant, so it is the placing of the element's text against <code>fillText()</code> at a whole pixel, not the widths.</td></tr>
<tr><td>26.4</td><td>A shader raising an uploaded element in an <code>RGBA16F</code> texture</td><td>4.00 inside the raised box, 1.00 beside it (measured)</td><td><code>texElementSubImage2D()</code> gives 8 bits, so the gain is applied in the shader, as on the WebGPU route of <code>/hdr-glow/</code>.</td></tr>
<tr><td>26.4</td><td><code>drawingBufferStorage(gl.RGBA16F, w, h)</code> on a drawable WebGL canvas</td><td>accepted, and the drawing buffer reads 4.00 after the bloom composite (measured)</td><td>Colour space <code>display-p3</code>. <code>drawingBufferToneMapping()</code> is absent with no flag and accepts <code>extended</code> with the flag.</td></tr>
<tr><td>26.4</td><td>That canvas on screen in the test browser</td><td>empty (measured)</td><td>With software compositing the canvas shows nothing and the console logs <code>GL_INVALID_OPERATION: glReadPixelsRobustANGLE: Invalid format and type combination</code> for each frame. With an 8-bit drawing buffer the same frame is shown. The page therefore asks for the float buffer at the start only where <code>(dynamic-range: high)</code> matches, and has a control for both.</td></tr>
<tr><td>26.4</td><td>Bloom</td><td>works in 8-bit output (measured by screenshot)</td><td>Bright pass above 1.0, two blur rounds at a quarter of the size, composite. The map view colours the badge, the button, the word and the bars.</td></tr>
<tr><td>26.5</td><td>A registered <code>&lt;custom-ident&gt;</code> read with <code>getComputedStyle()</code></td><td>the name (measured)</td><td>The page looks it up in <code>{ none, wave, split, lines }</code> and sets one float uniform. Editing the rule in the shown <code>&lt;style&gt;</code> element changes the effect on the next frame.</td></tr>
<tr><td>26.5</td><td>The same property in a 1 s linear transition</td><td><code>none</code> at 0.25 s, <code>wave</code> at 0.75 s; a registered number read 0.25 and 0.75 (measured)</td><td>So an effect change cannot be cross-faded by the property itself.</td></tr></tbody></table>
<h3>On the test phone (A159, experimental features flag on), reported 2026-11-22</h3>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Is a WebGL canvas with an <code>RGBA16F</code> drawing buffer shown</td><td>yes (reported)</td><td>Status line: "Drawing buffer: RGBA16F, display-p3, tone mapping: extended". The page chose it at the start, so <code>(dynamic-range: high)</code> matches.</td></tr>
<tr><td>Are the raised parts brighter than white</td><td>yes (reported)</td><td>"Searing white". At a headroom of 4.0 and a bloom of 1.0 the labels were hard to make out. The page now starts at 2.5 and 0.4.</td></tr>
<tr><td>The same scene with the 8-bit drawing buffer</td><td>flat white where raised, labels lost (reported, screenshot)</td><td>Each channel was cut off at 1.0, so the button, the badge and their white labels were all 1.0. The composite now divides such a pixel by its largest channel, which keeps the hue. Measured by screenshot in C157 after the change: blue button, red badge, white labels. Not yet seen on the phone.</td></tr>
<tr><td>Labels on the float buffer route</td><td>"Deploy", the "7" and the word BRIGHTER in the strip are readable; the word is "very clear" (reported, 09:59)</td><td>The word is at the headroom value on a strip of 1.0, so a difference above white alone carries it. The report came within a minute of the preview with the lower defaults (2.5 and 0.4) being deployed, so which defaults it was read at is not certain.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Stale click targets when one canvas serves several experiments (row 4 of the table). The first build was clicked through.</li>
<li>The first build asked for the float drawing buffer always, and every screenshot of that experiment was empty. The scene texture and the drawing buffer both read 4.00, so the loss is between the buffer and the screen in the software compositor.</li>
<li>A float drawing buffer has to be asked for again after the canvas is resized, and <code>ElementGL.begin()</code> has to run again after <code>drawingBufferStorage()</code> because the buffer is new.</li>
<li>Playwright's screenshot is slower than a 750 ms page turn in software rendering. The turn was photographed by freezing <code>performance.now()</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>A159 on the test phone: the other four experiments, and the 8-bit drawing buffer after the change of 2026-11-22.</li>
<li>What <code>Summarizer</code> returns for the six tiles, and how long the model download takes. To verify: press "Use the Summarizer API" in a Chrome that has the model.</li>
<li><code>TextMetrics.getSelectionRects()</code> in Chrome 160 without a flag.</li>
<li>Touch selection of the top line of "Text rectangles" and of the book text.</li>
<li>Frame rate of the page turn and the bloom on a phone.</li></ul>
<h3>Open ideas</h3>
<ul><li>26.5 asked for the binding to move into <code>lib/shader-fx.js</code>. That file is shared and generates <code>lib/fx.js</code>, so it was not changed here. The binding is <code>readCards()</code> in the page, about 15 lines on top of <code>lib/css-uniforms.js</code>. Moving it needs a pull request that changes only the library.</li>
<li>26.1 named <code>/board/</code>. The zoom is built on its own 2D canvas here, so <code>/board/</code> is unchanged.</li>
<li>A book longer than about ten pages needs one element for each handful of pages, because one texture holds them all.</li></ul>
<p><a href="https://html-in-canvas.page/plan-followups/">Open Five follow-ups to the Chrome APIs plan</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Four games made of live elements</title>
<link>https://html-in-canvas.page/play/</link>
<guid isPermaLink="true">https://html-in-canvas.page/play/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drag and drop</category>
<category>drawElementImage</category>
<category>iframe</category>
<category>contenteditable</category>
<description>Draggable notes that leave the canvas with their drawn pixels as the drag image, a 16 by 16 picture whose pixels are checkboxes in a form, a same-origin &lt;iframe&gt; cut into a sliding puzzle whose tiles still scroll and click, and a contenteditable page with a corner that curls and shows the typed text in reverse.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/play/"><img src="https://html-in-canvas.page/play/social.jpg" width="1200" height="630" alt="The page &quot;Four games made of live elements&quot;"></a></p>
<p><strong>Question:</strong> When a canvas draws one element in several places, or leaves it out, where does input go: can a drawn card start a native drag, can nine tiles of one iframe each scroll and click, and can a page be typed on while part of it is drawn mirrored?</p>
<p><strong>Short answer:</strong> Yes for all three, with extra work each time. An element has one hit region and the element drawn last is on top, so the puzzle moves the iframe's region under the pointer and covers the rest with transparent elements, and the notebook ends each frame with a hidden draw of the page at its flat place. A drawn card started a native drag with a mouse. An emulated long press did not, so touch has a second route with pointer events.</p>
<p>
Four ideas from the "play" group of the <a href="https://html-in-canvas.page/elements/">element catalogue</a>: a hand of <code>draggable</code> cards that can be
dragged out of the canvas, a picture made of 256 checkboxes, a same-origin <code>&lt;iframe&gt;</code> cut into a sliding puzzle, and a
<code>contenteditable</code> page whose corner curls. Each one draws a single element in several places or leaves an element out of
the drawing, so what I wanted to find out is where input goes when the picture and the element no longer line up.
</p>
<h3>How it works</h3>
<p>All four demos use the same three facts about <code>drawElementImage()</code>:</p>
<ul>
<li><b>An element can be drawn many times, and it has one hit region.</b> Every draw moves the region to that draw. The pattern of the pixel editor, the nine tiles and the mirrored back of the page are extra draws. Each demo ends its frame with one more draw of the element at the place where input should go, inside an empty clip, which moves the region and adds no pixels.</li>
<li><b>Where two hit regions overlap, the element that was drawn last gets the input.</b> The order in the document doesn't decide it. The puzzle covers eight cells of the frame's region with transparent elements placed after the frame, and the notebook puts a transparent grip over the corner of the page the same way.</li>
<li><b>An element that isn't drawn keeps the region of its last draw.</b> A card that is being dragged, a page that isn't on top and a shield that isn't needed are moved out of the way with <code>updateElementGeometry()</code> and a transform that shrinks the region to a point.</li>
</ul>
<p>Dragging by touch is kept apart from scrolling with <code>touch-action</code> on the drawn elements: <code>none</code> on the cards, the form and the grip, and <code>pan-y</code> on the canvas round them. The browser applies the value of the drawn element under the finger.</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch at 412 px wide. Not yet run on a phone.</p>
<ul>
<li><b>A <code>draggable</code> element drawn by a canvas starts a native drag.</b> A mouse drag that began on the drawn card raised <code>dragstart</code> on the card. <code>dragover</code> and <code>drop</code> reached the tray outside the canvas, and <code>dragend</code> on the card reported <code>dropEffect</code> "move". The canvas and the drawn cards also take <code>dragover</code> and <code>drop</code>.</li>
<li><b>The canvas pixels of one card can be copied inside <code>dragstart</code>.</b> A draw outside the paint event is in the canvas at once, so the card is drawn alone, copied with <code>drawImage()</code> and the scene drawn again in one task. What the browser then shows as the drag image, with <code>setDragImage()</code> and without it, isn't verified: the test browser has no drag image to read. The checkbox under the tray switches between the two on a real device.</li>
<li><b>An emulated long press didn't start a drag.</b> A touch held for 0.9 s on a drawn card and then moved raised <code>pointerdown</code> and no <code>dragstart</code>. A long press does nothing in the headless browser outside a canvas either, so this says nothing about a phone. The page has a second route with pointer events for touch and pen, and the line under the demo counts each route.</li>
<li><b><code>touch-action</code> on a drawn element is applied where the element is drawn.</b> A touch that began on a card (<code>none</code>) moved the card and didn't scroll. A touch that began on the canvas beside the cards (<code>pan-y</code>) scrolled the page 97 px. The same held for the form of checkboxes and the canvas round it.</li>
<li><b>A checkbox in a drawn form is toggled by a tap, and a change made by script raises <code>paint</code>.</b> <code>changedElements</code> held the form, which is the <code>drawable</code> element, and not the box. <code>form.reset()</code> and a reset button raised <code>paint</code> too. The paint handler reads the picture from <code>FormData</code>.</li>
<li><b>An element drawn at a quarter of its size kept hard edges.</b> With <code>imageSmoothingEnabled</code> off, four 20 px columns drawn 5 px wide read 0, 255, 0, 255.</li>
<li><b>Where hit regions overlap, the element drawn last gets the input.</b> The order of the elements in the document didn't matter. A transparent element placed after the iframe took the pointer over that part of the frame.</li>
<li><b>One tile of an iframe takes real input.</b> With the frame's region placed under a tile, a click went to the button at the matching point of the frame, the wheel scrolled the frame 90 px, and a touch drag scrolled it. A scroll inside the frame raised <code>paint</code> on the canvas, so all nine tiles followed.</li>
<li><b>Hit regions moved in <code>pointerdown</code> change where the same touch goes.</b> A touch that began on a shield, which then moved the frame's region under the finger, scrolled the frame by 35 px in that same gesture, and its tap was delivered to the frame as a trusted <code>click</code>. The page also has its own route (the frame document's <code>elementFromPoint()</code> and <code>click()</code>), used only if no trusted click arrives within 120 ms. The line under the puzzle counts both.</li>
<li><b><code>drawElementImage()</code> accepts a reflection.</b> The pixels are mirrored, and so are <code>getBoundingClientRect()</code> and <code>elementFromPoint()</code> for the element's children, until the next draw.</li>
<li><b>A <code>contenteditable</code> element drawn in two pieces takes the caret at its flat place.</b> A tap on the drawn page focused it, typed text was added, and each key raised <code>paint</code>, which redrew the flat part and the mirrored back. A page that isn't on top keeps its text and isn't drawn.</li>
<li><b>Not verified:</b> everything on a phone. In particular whether a long press on a drawn card starts a native drag on Android and what the drag image shows, a drop into a second window, the on-screen keyboard over the notebook and over the text field in the puzzle, touch selection handles on the curled page, and the speed of 42 small draws of the form in each frame while a ring is moving.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/play.md">findings/play.md</a> in the repository.</p>
<p>The four ideas of the "play" group of the element catalogue (group 20 of the backlog in PLAN.md). Measured in headless Chromium 157 (C157) on 2026-11-21 with a mouse, a keyboard and emulated touch at 412 px wide. The page's nine live checks pass there, and <code>node tools/play/check.mjs</code> drives the four demos with real input (26 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: when a canvas draws one element in several places, or leaves it out, where does input go?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Native drag from a <code>draggable</code> element that a canvas draws (mouse)</td><td>works</td><td><code>dragstart</code> was raised on the drawn card. <code>dragover</code> and <code>drop</code> reached a plain element outside the canvas, and <code>dragend</code> on the card reported <code>dropEffect</code> "move". Three types arrived: <code>text/plain</code>, <code>text/html</code> and a custom type.</td></tr>
<tr><td>The canvas and the drawn cards as drop targets</td><td>works</td><td><code>dragover</code> and <code>drop</code> are raised on the card under the pointer or on the canvas. A card dropped in the hand is moved to that index. Text dropped from elsewhere becomes a new card.</td></tr>
<tr><td>The canvas pixels of one card as the drag image</td><td>built, the image itself not verified</td><td>Inside <code>dragstart</code> the canvas is reset, the one card is drawn, the region is copied to a plain canvas with <code>drawImage()</code> and the scene is drawn again. The copy holds the card alone (live check: alpha 0 where the other box is). The copy is passed to <code>setDragImage()</code>. The test browser shows no drag image, so what a person sees is not verified. A checkbox on the page switches to the browser's own image for comparison.</td></tr>
<tr><td>Native drag from a long press (CDP touch, held 0.9 s, then moved)</td><td>no <code>dragstart</code></td><td>A long press does nothing in the headless browser outside a canvas either. Not a result about Android.</td></tr>
<tr><td>Second route for touch and pen</td><td>pointer events</td><td>A finger that moves 8 px on a card starts it. The same copied pixels follow the finger in a fixed plain canvas, and the same payload goes to the tray. Driven with CDP touch: 1 drag, card removed, note added.</td></tr>
<tr><td><code>touch-action</code> on a drawn element</td><td>applied at the drawn place</td><td>Cards, the form and the grip have <code>none</code>, the canvas has <code>pan-y</code>. A touch on a card moved it with 0 px of scroll. A touch on the canvas beside the cards scrolled the page 97 px, and beside the form 105 px.</td></tr>
<tr><td>Tap on a checkbox in a drawn form</td><td>toggles it</td><td>One tap, one box. A second tap cleared it.</td></tr>
<tr><td>A box checked by script</td><td>raises <code>paint</code></td><td>1 paint event. <code>changedElements</code> held the <code>&lt;form&gt;</code> (the drawable element), not the <code>&lt;input&gt;</code>. <code>form.reset()</code> raised 1 paint event.</td></tr>
<tr><td>The picture as a form value</td><td><code>FormData</code> read in the paint handler</td><td>The handler compares the set of checked boxes with the last one and starts a ring on each box that changed. No listener is used for the picture. The drag-to-draw listener only writes <code>checked</code>.</td></tr>
<tr><td>The form drawn again at 1/4 size as a pattern</td><td>hard edges</td><td><code>drawElementImage(form, x, y, 64, 64)</code> with <code>imageSmoothingEnabled</code> off. Live check: four 20 px columns drawn 5 px wide read 0, 255, 0, 255.</td></tr>
<tr><td>Which element gets input where two hit regions overlap</td><td>the one drawn last</td><td>Two overlapping boxes, drawn in both orders in two canvases. <code>elementFromPoint()</code> returned the one drawn last each time. Real mouse clicks agreed in a scratch page. Document order did not decide.</td></tr>
<tr><td>One same-origin iframe drawn as nine tiles</td><td>works</td><td>Each tile is the whole frame drawn through a clip of one square at an offset.</td></tr>
<tr><td>Input to a tile</td><td>the frame's region is placed under the active tile</td><td>A hidden draw of the frame at the offset of the active tile. Eight transparent drawable elements ("shields") are placed after it over the other cells. With a mouse, <code>pointermove</code> on a shield makes that tile active before a button is pressed, so the click goes into the frame itself.</td></tr>
<tr><td>Click, wheel and touch scroll on a tile</td><td>work</td><td>A click reached the button at the matching point of the frame. The wheel scrolled the frame 90 px. A scroll inside the frame raised <code>paint</code> (1 event, <code>changedElements</code> held the iframe) and every tile showed the new position.</td></tr>
<tr><td>First touch on a tile that is not active</td><td>the same touch reaches the frame</td><td>The shield's <code>pointerdown</code> listener makes the tile active and redraws at once. That same touch then scrolled the frame 35 px, and its tap arrived in the frame as a trusted <code>click</code>. In an earlier scratch page that did not toggle an attribute after moving the regions, the click went to the iframe element in the outer document instead.</td></tr>
<tr><td>The page's own tap route</td><td>used when no trusted click arrives in 120 ms</td><td>The page maps the point into the frame, asks the frame document's <code>elementFromPoint()</code> and calls <code>click()</code> on a control or slides the tile. In C157 it was not needed (0 uses in the driven run). It is kept for the phone, and the line under the demo counts both routes.</td></tr>
<tr><td><code>drawElementImage()</code> through a reflection (<code>scale(-1, 1)</code>, or the matrix of a reflection about a line)</td><td>works</td><td>Pixels are mirrored. <code>getBoundingClientRect()</code> of a child reports the mirrored place and <code>elementFromPoint()</code> finds the child there.</td></tr>
<tr><td>A <code>contenteditable</code> element drawn in two pieces (flat part and mirrored back)</td><td>types and takes the caret</td><td>The last draw of the page each frame is a hidden draw at the flat place. A tap focused the page, 47 typed characters were added, and the canvas changed with each key.</td></tr>
<tr><td>Text added to a <code>contenteditable</code> element by script, no focus</td><td>raises <code>paint</code></td><td>1 event, <code>changedElements</code> held the element. A <code>Range</code> over the new word reported its box at the drawn place.</td></tr>
<tr><td>Pages that are not on top</td><td>kept, not drawn</td><td>They are parked with <code>updateElementGeometry()</code> and a transform that shrinks the region to a point. Text typed on page 1 was still there after turning to page 2 and back.</td></tr>
<tr><td>A lost context</td><td>plain elements</td><td>One <code>contextlost</code> event on one canvas stops all four demos and shows the cards, the form, the iframe and the pages as plain HTML. Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>.card</code> is a class in <code>shared/style.css</code>. The notes are <code>.pcard</code>.</li>
<li>A tap on a shield was handled twice: once by the page's own route in <code>pointerup</code>, and once by the frame, which got a trusted <code>click</code> from the same tap. A tile slid to the gap and back. The page's route now waits 120 ms and is cancelled by the frame's click.</li>
<li><code>elementFromPoint()</code> kept returning the iframe at a point after a shield was placed there (the remembered hit test of C157). Real input went to the shield. The demo toggles an attribute on the frame and the shields after each move.</li>
<li>The drag image cannot be made by copying the card's rectangle out of the scene, because the neighbours overlap it. The card is drawn alone first.</li>
<li><code>setDragImage()</code> needs an element that is laid out. The copy is a canvas with <code>position: fixed</code> at -400 px, and the touch route moves that same element under the finger.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome on Android: whether a long press on a drawn card starts a native drag, and what the drag image shows with <code>setDragImage()</code> and without it. Open <code>/play/#drag</code>, long press a card, and read the line under the tray.</li>
<li>A drop into a second window. Open <code>/play/</code> in two windows on a desktop and drag a card to the other window's tray. The card should leave the first window when <code>dragend</code> reports "move".</li>
<li>The drag image on a desktop with a real display.</li>
<li>On the phone: whether the first touch on a tile scrolls the frame, and which tap route the line under the puzzle counts.</li>
<li>The on-screen keyboard over the notebook and over the text field in the puzzle frame, and touch selection handles on a page whose corner is curled.</li>
<li>Frame rate of the pixel editor on the phone: 42 small draws of the form per frame while a ring is moving.</li></ul>
<p><a href="https://html-in-canvas.page/play/">Open Four games made of live elements</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Shaders that join the native controls and the video frame</title>
<link>https://html-in-canvas.page/player-fx/</link>
<guid isPermaLink="true">https://html-in-canvas.page/player-fx/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>texElementSubImage2D</category>
<category>texImage2D(video)</category>
<category>::-webkit-media-controls</category>
<category>WebGL 2</category>
<description>One &lt;video controls&gt; gives a WebGL canvas its controls and its frame as two textures. The controls bend, melt into and light the picture, and the page finds where the play button and timeline are without script access to them.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/player-fx/"><img src="https://html-in-canvas.page/player-fx/social.jpg" width="1200" height="630" alt="The page &quot;Shaders that join the native controls and the video frame&quot;"></a></p>
<p><strong>Question:</strong> Can one shader work on the native controls and the video frame as separate inputs, and can an effect start at one control when no script can reach it?</p>
<p><strong>Short answer:</strong> Yes. The controls and the frame are two textures from one element. Each named part is found by giving it a flat colour for one paint and reading the picture back.</p>
<p>
One <code>&lt;video controls&gt;</code> gives a WebGL canvas two textures: its controls, and its frame. One fragment shader reads both.
The page also finds where the play button, the timeline and four other parts are, although no script can reach them, so an effect can start at one part.
</p>
<h3>How it works</h3>
<ul>
<li>The video is a child of the canvas and fills it. <code>object-position: -9999px 0</code> moves its frame out of its box, so the browser paints only the controls for it. That picture goes into one texture.</li>
<li><code>texImage2D(video)</code> on the same element still gives the frame. That's the second texture. One decoder serves both.</li>
<li>The controls are drawn where the element lies, so taps reach them with no extra work.</li>
<li>To find one part, the page adds a class for a single paint. The class gives each part a flat colour through its pseudo-element. The page uploads that picture to a spare texture, reads it back, and takes the bounding box of each colour. The spare texture is never drawn to the screen.</li>
<li>The shader gets the boxes as uniforms, with the playback position and the time since the last play or pause.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: controls and frame as two textures from one element.</strong> A shader can refract the frame through the controls, fill the controls with the frame, or light the frame from a control.</li>
<li><strong>Works: one part used as a shape.</strong> With the box of the play button known, the shader reads its glyph out of the controls texture and draws it at any size. The glyph is the browser's, so it changes between play and pause without any code here.</li>
<li><strong>Works: the position of one part.</strong> A colour per pseudo-element and one readback give the box of the play button, timeline, mute button, fullscreen button and both time displays. The boxes are measured, so they follow the layout the browser chose, including a touch layout.</li>
<li><strong>Works: the browser's own fade is an input.</strong> During playback the browser fades the buttons. The fade arrives in the texture as alpha, so the melt effect shrinks the shapes with it.</li>
<li><strong>Works: everything the player paints is in the controls texture.</strong> The loading ring and the menu are there too, so the effects apply to them with no extra code.</li>
<li><strong>Limit: parts with no pseudo-element name can't be found.</strong> The menu button and the row that holds the buttons have internal names only.</li>
<li><strong>Limit: one part can't be drawn by itself.</strong> The shader can treat the area of a part differently. It can't have the play button as a texture of its own. A second copy of the element with every other part set to <code>display: none</code> would give that, at the cost of another video element.</li>
<li><strong>Limit: the boxes go stale.</strong> They are measured after loading, on resize and when the controls come back. A layout change between those moments isn't seen.</li>
<li><strong>Not built:</strong> a WebGPU version of this shader. The page uses WebGL 2.</li>
<li><strong>Not verified here:</strong> a hardware-decoded frame through <code>texImage2D(video)</code> on Android, the boxes found in the touch layout of the controls, and the frame rate on a phone.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-and-sound.md">findings/video-and-sound.md</a> in the repository.</p>
<h3>One shader over the controls and the frame (<code>/player-fx/</code>)</h3>
<p>Paul asked for effects where the controls and the picture work on each other, for example the play button melding in and out of the video. One <code>&lt;video controls&gt;</code> fills a WebGL 2 canvas with its frame moved out of its box.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>texElementSubImage2D()</code> for the controls and <code>texImage2D(video)</code> for the frame, same element</td><td>two textures, one decoder</td><td>The controls texture is clear where there is no control. The loading ring and the menu are in it too.</td></tr>
<tr><td>Hit testing with a WebGL canvas</td><td>needs <code>updateElementGeometry()</code></td><td>A WebGL draw does not place the element. With an identity <code>canvasTransform</code> taps reach the native controls.</td></tr>
<tr><td>Position of one part</td><td>found</td><td>A class gives each named part a flat colour for one paint. That picture goes to a spare texture, is read back, and each colour's bounding box is the part. Play button, timeline, mute, fullscreen and both time displays. The coloured picture never reaches the screen (0 pixels in three frames).</td></tr>
<tr><td>Glyph of one part as a shape</td><td>works</td><td>The shader reads the play button's glyph out of its measured box and draws it large as a lens. The browser swaps the glyph between play and pause.</td></tr>
<tr><td>Effects</td><td>six</td><td>Meld (large play glyph that shrinks into the button on play), glass (frosted bar, each control refracts the frame), melt (thickened shapes filled with the inverted frame that run downwards on play and pause), ripple (wave from the play button's centre), light (the frame lit from the timeline thumb), outlines of the measured parts.</td></tr>
<tr><td><code>WEBGL_lose_context.loseContext()</code> on a check fixture</td><td>the tab crashed</td><td>Chromium 157. A smaller case with one canvas did not crash, so the cause is not known. The checks leave the context to the garbage collector.</td></tr></tbody></table>
<p>Not built: a WebGPU version of the shader. Not found by the colour method: parts with internal names only (menu button, the row of buttons). Not verified: <code>texImage2D(video)</code> with a hardware decoder on Android, the boxes in the touch layout, the frame rate on a phone.</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-lab.md">findings/video-lab.md</a> in the repository.</p>
<h3>The <code>/player-fx/</code> shader in WebGPU (22.5)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>WGSL port of the shader (meld, glass, ripple, outlines)</td><td>compiles and draws, off screen</td><td>Meld changes 87 % of the picture of a paused player, glass 13 to 16 %, outlines 95 %.</td></tr>
<tr><td>Controls as a texture: <code>GPUQueue.drawElementImageToTexture()</code> of the element with the frame moved out of its box</td><td>works</td><td>The texture has straight alpha.</td></tr>
<tr><td>Frame as a texture: <code>copyExternalImageToTexture({ source: video })</code></td><td>fails on the software adapter</td><td>The fallback, <code>createImageBitmap(video)</code> then a copy of the bitmap, gave frame 60 as asked. Same result as on <code>/gpu-video/</code>.</td></tr>
<tr><td>Finding the parts through WebGPU: the probe picture into a texture with <code>COPY_SRC</code>, <code>copyTextureToBuffer()</code>, one <code>mapAsync()</code></td><td>works</td><td>Play, timeline, mute and fullscreen were found. <code>GPUElementTexture</code> from <code>lib/gpu-util.js</code> has no <code>COPY_SRC</code>, so the probe has its own texture.</td></tr>
<tr><td>The player on screen</td><td>not verified</td><td><code>webgpu()</code> refuses the software adapter. The page then draws the frame and the controls with the 2D context and says why.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/player-fx/">Open Shaders that join the native controls and the video frame</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Parts of the native media player</title>
<link>https://html-in-canvas.page/player-parts/</link>
<guid isPermaLink="true">https://html-in-canvas.page/player-parts/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>::-webkit-media-controls</category>
<category>:paused</category>
<category>:has()</category>
<category>drawImage(video)</category>
<description>The controls of &lt;video&gt; are a closed shadow tree. Restyle them with pseudo-elements, let :paused and :seeking drive a shader through CSS, and draw the controls as a layer apart from the picture.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/player-parts/"><img src="https://html-in-canvas.page/player-parts/social.jpg" width="1200" height="630" alt="The page &quot;Parts of the native media player&quot;"></a></p>
<p><strong>Question:</strong> The native media controls are a shadow tree a page can't open. Can a canvas restyle their parts, react to the player's state, or draw the controls apart from the picture?</p>
<p><strong>Short answer:</strong> Pseudo-element rules are drawn. State pseudo-classes drive a shader through <code>:has()</code> where the browser has them. A video reduced to its controls can be drawn anywhere. No single part can be reached from script.</p>
<p>
Chrome builds the controls of <code>&lt;video&gt;</code> and <code>&lt;audio&gt;</code> as elements in a shadow tree that pages can't open. I wanted to know what
a canvas can still do with them: restyle the parts, let the player's state drive a shader, and draw the controls apart from the picture.
</p>
<h3>How it works</h3>
<ul>
<li>The controls can't be reached as elements. They can be reached with CSS: about twenty <code>::-webkit-media-controls-*</code> pseudo-elements, and <code>::cue</code> for captions. A canvas draws whatever those rules produce.</li>
<li>The state of the player is visible to CSS through <code>:paused</code>, <code>:seeking</code>, <code>:muted</code> and others where the browser has them. <code>:has()</code> carries that state to a parent, and a registered custom property carries it into a shader.</li>
<li>A canvas can get a video frame two ways: as part of the element's picture, with controls and captions, or bare with <code>drawImage(video)</code>. Part 3 uses the bare frame for the picture and reduces the element to its controls.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: pseudo-element rules are drawn.</strong> Background, colour, <code>accent-color</code>, <code>border-radius</code>, <code>display: none</code> and <code>zoom</code> on <code>::-webkit-media-controls-*</code> parts all show in the canvas, on <code>&lt;video&gt;</code> and <code>&lt;audio&gt;</code>, and the restyled controls keep working.</li>
<li><strong>Works behind a flag: state pseudo-classes.</strong> <code>:paused</code>, <code>:playing</code>, <code>:seeking</code>, <code>:muted</code>, <code>:buffering</code>, <code>:stalled</code> and <code>:volume-locked</code> aren't valid selectors in Chromium 157 by default. chromestatus lists them for Chrome 158. In 157 with experimental web platform features on they work, and <code>:has(video:paused)</code> on a canvas child changes a custom property that the shader reads. <code>:picture-in-picture</code> and <code>:fullscreen</code> work without the flag. Without the pseudo-classes, event listeners that set three attributes give the same result.</li>
<li><strong>Works: HTML controls with no state code.</strong> In part 3 the labels of the HTML play and mute buttons and the busy ring are CSS <code>content</code> and <code>display</code> rules under <code>:has(#lv:paused)</code>, <code>:has(#lv:muted)</code> and <code>:has(#lv:buffering)</code>. The style change alone raises <code>paint</code>. Position and time still need script: CSS has no value for <code>currentTime</code>.</li>
<li><strong>Works: the controls as their own layer.</strong> <code>object-position: -9999px 0</code> moves the frame out of the element's box and leaves the controls on a clear background. An 80 px tall <code>&lt;video&gt;</code> is then a control strip. The canvas draws the frame from <code>drawImage(video)</code> with any filter, and draws the strip anywhere, at any size. Hit testing follows the strip.</li>
<li><strong>Limit: no script access.</strong> <code>video.shadowRoot</code> is <code>null</code> and <code>attachShadow()</code> throws <code>NotSupportedError</code>. One part can't be given <code>drawable</code>, measured, or drawn by itself. The page can't ask where the play button is.</li>
<li><strong>Limit: nothing can be put inside.</strong> Children of <code>&lt;video&gt;</code> aren't rendered, so a canvas or any HTML can't sit among the controls. HTML over the video is a sibling in the same drawn element (see <a href="https://html-in-canvas.page/overlay/">HTML overlays on video</a>).</li>
<li><strong>Limit: the controls stay inside the element's box.</strong> A transform on the panel that moves it below the video is clipped. To put controls outside the picture, shrink the element to the controls (part 3) instead of moving the controls.</li>
<li><strong>Limit: the buttons of a video fade during playback.</strong> After about three seconds of playback with no pointer over the video, Chrome fades the controls and then sets the panel to <code>display: none</code>. <code>opacity: 1 !important</code> on <code>::-webkit-media-controls-panel</code> and <code>::-webkit-media-controls-timeline</code> keeps the timeline. The row of buttons is <code>::-internal-media-controls-button-panel</code>, a name pages can't use, so no rule keeps it. It comes back when the pointer moves over the strip or the strip is tapped.</li>
<li><strong>Works: an audio element as a control strip that never fades.</strong> The controls of <code>&lt;audio&gt;</code> stay visible. An audio element playing the same file, with a muted video that copies its play, pause, seek and speed, gives native controls under a picture the canvas draws. It has no fullscreen or captions button, and the two decoders need a drift correction.</li>
<li><strong>Limit: one element, one hit region.</strong> The control strip can be moved and scaled as a whole. Its buttons can't be placed one by one.</li>
<li><strong>Native against HTML controls.</strong> Native controls bring the menu, captions switch, playback speed, Picture-in-Picture, keyboard and accessibility for no code, and can only be restyled part by part. Controls written in HTML take about 25 lines for play, seek, time and mute, can be laid out and drawn piece by piece, and have none of the rest until it's written.</li>
<li><strong>Not verified here:</strong> which state pseudo-classes Chrome 159 on Android has by default, and how the touch layout of the controls (larger buttons, double-tap to seek) fits an 80 px strip.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-and-sound.md">findings/video-and-sound.md</a> in the repository.</p>
<h3>Parts of the native player (<code>/player-parts/</code>)</h3>
<p>Chrome builds the controls of <code>&lt;video&gt;</code> and <code>&lt;audio&gt;</code> as elements in a user-agent shadow tree. The question was what a canvas can do with those parts.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Rules on <code>::-webkit-media-controls-panel</code>, <code>-timeline</code>, <code>-play-button</code>, time displays</td><td>drawn in the canvas</td><td>Background, colour, <code>accent-color</code>, <code>border-radius</code>, <code>display: none</code>, <code>zoom</code>. Same on <code>&lt;audio&gt;</code>. The restyled controls keep working.</td></tr>
<tr><td><code>:paused</code>, <code>:playing</code>, <code>:seeking</code>, <code>:muted</code>, <code>:buffering</code>, <code>:stalled</code>, <code>:volume-locked</code></td><td>not valid selectors by default</td><td>Valid with experimental web platform features on. Then <code>:has(video:paused)</code> on the drawn element sets a registered custom property, a CSS transition moves it, and the shader reads it. No script takes part. <code>:picture-in-picture</code> and <code>:fullscreen</code> work without the flag.</td></tr>
<tr><td>The same with attributes set from <code>play</code>, <code>pause</code>, <code>seeking</code>, <code>seeked</code>, <code>volumechange</code></td><td>works</td><td>The fallback the page uses when <code>CSS.supports('selector(:paused)')</code> is false.</td></tr>
<tr><td><code>object-fit: none; object-position: -9999px 0</code> on the video</td><td>the frame leaves, the controls stay</td><td><code>drawImage(video)</code> still gives the frame. An 80 px tall <code>&lt;video&gt;</code> is then a strip of controls on a clear background.</td></tr>
<tr><td>Frame from <code>drawImage(video)</code> with <code>ctx.filter</code>, controls from <code>drawElementImage()</code></td><td>two layers</td><td>The filter does not reach the controls. The strip can be drawn under the picture, over it, or 1.5 times larger, and takes hits where it is drawn.</td></tr>
<tr><td>Keeping the video's controls visible during playback</td><td>timeline only</td><td>Chrome adds a class to the panel, fades it, then sets <code>display: none</code>. <code>opacity: 1 !important</code> on the panel and the timeline keeps the timeline. The row of buttons is <code>::-internal-media-controls-button-panel</code>, which author CSS cannot name. Focus on the video keeps the buttons after <code>focus()</code> with no pointer input, but not after a mouse click.</td></tr>
<tr><td><code>&lt;audio controls&gt;</code> playing the same file, muted video following it</td><td>controls never fade</td><td>Play, pause, seek and speed are copied from the audio element's events, with a drift correction on <code>timeupdate</code>. No fullscreen or captions button.</td></tr>
<tr><td><code>video.shadowRoot</code>, <code>video.attachShadow()</code></td><td><code>null</code>, <code>NotSupportedError</code></td><td>No part can be given <code>drawable</code>, measured, or drawn by itself.</td></tr>
<tr><td>HTML or a canvas as a child of <code>&lt;video&gt;</code></td><td>not rendered</td><td>Children of a media element are fallback content. Nothing can be put among the controls.</td></tr>
<tr><td><code>transform</code> on the panel to move it below the video</td><td>clipped to the video's box</td><td>Shrink the element to its controls instead.</td></tr></tbody></table>
<p>Compared with controls written in HTML: the native ones bring the overflow menu, captions switch, playback speed, Picture-in-Picture, keyboard handling and accessibility for no code, and can be restyled only through the named parts. HTML controls take about 25 lines for play, seek, time and mute, and each one can be drawn and placed by itself.</p>
<p>While checks run, the shared fixture box covered the bottom left of the window and took taps meant for the page. The four media pages now set <code>pointer-events: none</code> on it, and switch it back only for the synchronous <code>elementFromPoint()</code> call of a hit-test check.</p>
<p>Reported from Chrome on Android (2026-11-21): with the checks starting on load, videos on these pages errored and the page jumped. A check fixture is one or two more playing videos beside the three on the page, and a phone has a small number of hardware decoders. Since then the checks on the four media pages wait for a tap, each player on <code>/player-parts/</code> gets its file only when it is scrolled near and pauses when it leaves the window, and a media error is written under the player with a button to load the file again. Whether that is the whole cause is not confirmed on the device.</p>
<p><a href="https://html-in-canvas.page/player-parts/">Open Parts of the native media player</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Native popovers anchored to controls on a tilted panel</title>
<link>https://html-in-canvas.page/popovers/</link>
<guid isPermaLink="true">https://html-in-canvas.page/popovers/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>popover</category>
<category>commandfor</category>
<category>interestfor</category>
<category>anchor positioning</category>
<category>updateElementGeometry</category>
<description>Buttons on a panel drawn in perspective open a real popover, a hint and a modal dialog through commandfor and interestfor. CSS anchor positioning keeps each popover on its drawn button while the panel turns.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/popovers/"><img src="https://html-in-canvas.page/popovers/social.jpg" width="1200" height="630" alt="The page &quot;Native popovers anchored to controls on a tilted panel&quot;"></a></p>
<p><strong>Question:</strong> Do native popovers, hints and dialogs open from controls that a canvas draws in perspective, and does CSS anchor positioning place them at the drawn control?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157: the anchor rectangle is the bounding box of the drawn quad and an open popover follows it as the panel turns. Chromium 153 anchors to the layout box.</p>
<p>
The panel is HTML that a canvas draws on a quad in perspective. Its buttons open browser-native top-layer UI with no script: <b>Scenes</b> opens a <code>popover</code> through
<code>commandfor</code>, <b>?</b> shows a <code>popover="hint"</code> through <code>interestfor</code> (hover, keyboard focus, or a long press on touch), and <b>Turn off</b> opens a modal
<code>&lt;dialog&gt;</code>. The popovers are placed with CSS anchor positioning against buttons that are only pictures on a texture. Move the two sliders on the panel, or switch on the swing,
and an open popover follows its button.
</p>
<h3>How it works</h3>
<p>The panel is one <code>drawable</code> child of the canvas, uploaded as a texture and drawn on a quad through a matrix with perspective. The same matrix goes to <code>updateElementGeometry()</code> in each <code>paint</code> event. From then on the browser's hit tests, focus rings and anchor rectangles for the panel's buttons use the drawn place. The popovers and the dialog are ordinary elements outside the canvas; <code>commandfor</code> and <code>interestfor</code> open them and CSS anchor positioning places them. The canvas repaints every frame only while the panel swings or a popover is open.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 the anchor rectangle of an element inside a drawn canvas child is the bounding box of its drawn quad. With a 50 degree turn and perspective, a 60 by 30 pixel button gave an
anchor of 34 by 29 pixels at the projected place, and a popover with <code>position-area: bottom</code> sat under it.</li>
<li>An open popover moves with its button when the panel's matrix changes. The page calls <code>updateElementGeometry()</code> in each <code>paint</code> event and does nothing else for the popover.</li>
<li><code>commandfor</code> with <code>toggle-popover</code>, <code>hide-popover</code> and <code>show-modal</code> works from a button drawn in perspective, by mouse, touch and keyboard. The target doesn't
have to be in the canvas.</li>
<li>The range inputs on the panel can be dragged while the panel turns under the pointer, because each new matrix moves the hit box as well.</li>
<li>The popover's arrow flips with an <code>anchored(fallback: flip-block)</code> container query when <code>position-try-fallbacks</code> moves the popover above the button.</li>
<li>Chromium 153 keeps the anchor at the element's layout box, so there the popovers open at the panel's untransformed place. Chrome 159 on the phone isn't verified.</li>
<li>The popovers and the dialog are drawn by the browser above the canvas. The canvas can't draw over them or bend them.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/popovers.md">findings/popovers.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21, with synthetic mouse, touch and keyboard input. Not yet run on the test phone.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Anchor rectangle of an element inside a drawn canvas child</td><td>the bounding box of its drawn quad</td><td>With a 50 degree turn and perspective, a 60 by 30 pixel button anchored a popover at a 34 by 29 pixel box at the projected place. <code>getBoundingClientRect()</code> returns the same box. Chromium 153 uses the layout box.</td></tr>
<tr><td>An open popover while the matrix changes</td><td>follows</td><td><code>updateElementGeometry()</code> in each <code>paint</code> event is enough. No script positions the popover.</td></tr>
<tr><td><code>commandfor</code> with <code>toggle-popover</code>, <code>hide-popover</code>, <code>show-modal</code> from a button drawn in perspective</td><td>works</td><td>By mouse, tap and keyboard. The target is outside the canvas.</td></tr>
<tr><td><code>interestfor</code> on a drawn button</td><td>works</td><td>The hint opened on hover over the drawn place and on keyboard focus. Long press on touch is not verified.</td></tr>
<tr><td>Dragging a range input on a panel that turns under the pointer</td><td>works</td><td>The thumb moved with a synthetic mouse drag while each <code>input</code> event changed the matrix.</td></tr>
<tr><td><code>anchored(fallback: flip-block)</code> container query on a popover anchored into a canvas</td><td>applies</td><td>The arrow moves to the other edge when <code>position-try-fallbacks</code> flips the popover. Seen in screenshots; no live check.</td></tr>
<tr><td>Hit testing a point of the demo that is outside the window</td><td>returns nothing</td><td><code>elementFromPoint()</code> needs the point in the viewport. The run button for checks that hit test the visible demo sits under the demo, not in the checks section.</td></tr></tbody></table>
<h3>Not verified</h3>
<ul><li>Chrome 159 on the test phone. Chromium 153 anchors to the layout box, so the phone may place the popovers at the panel's untransformed position. The page's third and fourth live checks report it.</li>
<li>Long press on touch for the <code>interestfor</code> hint.</li></ul>
<p><a href="https://html-in-canvas.page/popovers/">Open Native popovers anchored to controls on a tilted panel</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A video presenter over a slide made of DOM</title>
<link>https://html-in-canvas.page/presenter/</link>
<guid isPermaLink="true">https://html-in-canvas.page/presenter/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>alpha video</category>
<category>chroma key</category>
<category>getUserMedia</category>
<category>captureStream</category>
<category>WebGL 2</category>
<description>A video with transparency, or the camera with its background keyed out, drawn over HTML slides in one canvas. The slide's link, form and text work under the video, and the canvas is sent as a camera.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/presenter/"><img src="https://html-in-canvas.page/presenter/social.jpg" width="1200" height="630" alt="The page &quot;A video presenter over a slide made of DOM&quot;"></a></p>
<p><strong>Question:</strong> Can a person from a video with transparency, or from a camera with its background removed, be composed over a slide that is live DOM in one canvas that is also a stream, while the slide's links, form controls and text selection keep working under the person?</p>
<p><strong>Short answer:</strong> Yes. The video is drawn as pixels, so every hit goes to the slide. Alpha video, a chroma key and a difference key work. The browser's own segmentation mask wasn't offered by the test camera.</p>
<p>
The picture below is one canvas. It draws a slide that is HTML and, over it, a video with transparency: a clip with an alpha channel, or the camera with its background removed.
Tap the slide's link, fill in its form and select its text, including under the video. Drag the round handle to move the presenter. Pick an effect, then send the canvas as a camera or record it.
</p>
<h3>How it works</h3>
<ul>
<li>The slide is two elements of 640 by 360 layout pixels. The back one has the background and the body. The front one has the title. The presenter is drawn between them or after both.</li>
<li>The presenter is drawn from a <code>&lt;video&gt;</code> that isn't a child of the canvas. Nothing of it exists for hit testing, so every tap goes to the slide.</li>
<li>The clip with an alpha channel is drawn with a 2D context. A camera, the drawn figure and three of the effects need a shader. The page then makes a second canvas with a WebGL 2 context and moves the two slide elements into it.</li>
<li>The video doesn't invalidate the canvas, because it isn't in it. <code>requestVideoFrameCallback()</code> calls <code>requestPaint()</code> for each frame.</li>
<li>The chroma key compares the chroma of each pixel with a key colour. The difference key compares each pixel with a frame captured when the person was out of the picture.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering and its fake camera, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: the slide takes input under the presenter.</strong> A link, a radio button, a range input and a text field were used through the video's pixels, and text under it was selected. This holds on both routes.</li>
<li><strong>Works: alpha video by three routes.</strong> A <code>&lt;video&gt;</code> child of a drawable element, <code>drawImage(video)</code> and <code>texImage2D(video)</code> all keep the alpha of the VP9 clip.</li>
<li><strong>Works: chroma key and difference key in one shader.</strong> Both need no browser support beyond <code>texImage2D(video)</code>. The difference key needs a still camera and a captured background.</li>
<li><strong>Works: the composed canvas as a stream.</strong> <code>captureStream()</code> through <code>RTCPeerConnection</code> carries the slide and the presenter. <code>MediaRecorder</code> records it.</li>
<li><strong>Limit: a presenter that is a <code>&lt;video&gt;</code> element takes the taps.</strong> As a child of the slide it is hit on its clear pixels too. It needs <code>pointer-events: none</code>.</li>
<li><strong>Limit: the video raises no <code>paint</code>.</strong> A video outside the canvas gave 0 paints a second until the page called <code>requestPaint()</code> for each frame.</li>
<li><strong>Needed: <code>preserveDrawingBuffer</code> for the WebGL stream.</strong> Without it <code>captureStream()</code> of the WebGL canvas gave black frames, because the canvas is drawn only in its <code>paint</code> handler. The 2D canvas needs nothing.</li>
<li><strong>Limit: the bend effect moves pixels, not hit boxes.</strong> A control drawn up to 27 pixels from its place is still hit at its place.</li>
<li><strong>Not available here: segmentation by the browser.</strong> The fake camera lists neither <code>backgroundBlur</code> nor <code>backgroundSegmentationMask</code> in <code>getCapabilities()</code>. The mask route is written and hasn't run.</li>
<li><strong>Not verified here:</strong> a real camera, the two keys on a real background, hardware-decoded alpha video, and the frame rate of the shader on a phone. The checks above and the status line under the picture report them on your device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/presenter.md">findings/presenter.md</a> in the repository.</p>
<p>Chromium 157 headless (C157), software rendering and software video decoding, 2026-11-21. Phone emulation: 412 px wide, touch, device scale factor 2.625. Every camera result below comes from Chromium's fake camera (<code>--use-fake-device-for-media-stream</code>, label <code>fake_device_0</code>, 640×360, a flat green picture with a moving yellow-green wedge). No real camera was used. All results are measured unless a row says otherwise.</p>
<p>The page draws a slide (two <code>drawable</code> elements of 640×360 layout pixels: body and title) and a presenter video in one canvas with a fixed 640×360 buffer. The presenter comes from a <code>&lt;video&gt;</code> or a canvas that is not a child of the drawable canvas.</p>
<h3>Composition and input</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>VP9 alpha clip as a <code>&lt;video&gt;</code> child of a drawable element, <code>drawElementImage()</code></td><td>alpha kept</td><td>Of 1849 sampled points in the video's box, 1534 showed the slide and 315 the disc.</td></tr>
<tr><td><code>drawImage(video)</code> of the alpha clip after <code>drawElementImage(slide)</code></td><td>alpha kept</td><td>The 2D route of the page. 318 of 3600 points were the video.</td></tr>
<tr><td>Shadow of the presenter on the slide, 2D</td><td>works</td><td><code>shadowBlur</code> with the picture drawn 4000 px off the canvas and <code>shadowOffsetX</code> bringing only the shadow back. 194 more points of the slide were darker.</td></tr>
<tr><td><code>texImage2D(video)</code> of the alpha clip in WebGL 2</td><td>alpha kept</td><td>The clear corner of the video showed the slide. An edge pixel read back as alpha 252 with unmultiplied colour.</td></tr>
<tr><td>Link under the presenter's pixels, 2D route</td><td>hit</td><td><code>elementFromPoint()</code> returns the <code>&lt;a&gt;</code> at a point where the canvas shows the video. <code>caretRangeFromPoint()</code> returns a character offset in the link's text.</td></tr>
<tr><td>Tap on a link under the presenter (touch, demo)</td><td>received</td><td>3 of 3 taps on the 2D route, 1 of 1 on the WebGL route.</td></tr>
<tr><td>Radio button and text field under or beside the presenter, WebGL route (touch, demo)</td><td>work</td><td>The radio was checked by a tap. A tap on the text field focused it and typed text arrived.</td></tr>
<tr><td>Text selection by mouse drag across text under the presenter</td><td>works</td><td><code>getSelection().toString()</code> gave the whole sentence. The highlight is drawn in the canvas, under the presenter. Touch selection (long press) was not run.</td></tr>
<tr><td>Radio button under the keyed presenter, WebGL fixture</td><td>found and checked</td><td><code>elementFromPoint()</code> returns the <code>&lt;input&gt;</code> after <code>updateElementGeometry()</code>. A script click checks it and fires <code>change</code>. One <code>paint</code> follows with no <code>requestPaint()</code>.</td></tr>
<tr><td>Presenter as a <code>&lt;video&gt;</code> element over the link (child of the slide)</td><td>takes the hit</td><td><code>elementFromPoint()</code> on a clear pixel of the video returns <code>&lt;video&gt;</code>. With <code>pointer-events: none</code> on the video it returns <code>&lt;a&gt;</code>. Check row marked <code>expect: 'fail'</code>.</td></tr>
<tr><td>Title layer over the whole slide</td><td>does not block the body</td><td>The front layer has <code>pointer-events: none</code> and its <code>&lt;h2&gt;</code> has <code>auto</code>. Hits on empty parts of it reach the back layer.</td></tr>
<tr><td>Presenter between the two layers</td><td>works</td><td>Draw order back, presenter, front on both routes.</td></tr>
<tr><td>Moving the two <code>drawable</code> elements from the 2D canvas to a WebGL canvas and back with <code>append()</code></td><td>works</td><td>Form state is kept. A <code>paint</code> of the old canvas that still held a reference threw "The element can only be drawn into its nearest ancestor canvas", so each handler checks <code>parentNode</code>.</td></tr>
<tr><td><code>updateElementGeometry()</code> on a 640×360 buffer shown 354 px wide</td><td>unit is CSS pixels here</td><td>Identity gave a 640 px wide box. The page measures the unit and scales by <code>clientWidth / 640</code>.</td></tr>
<tr><td><code>getElementImageDefaultSize()</code> for a 640 px element in a 640 px buffer shown 320 px wide</td><td>1280×720</td><td>The size follows buffer pixels per CSS pixel, not the device scale factor.</td></tr></tbody></table>
<h3>Background removal</h3>
<table><thead><tr><th>Route</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>getCapabilities().backgroundBlur</code></td><td>not listed</td><td>Fake camera. <code>getSupportedConstraints().backgroundBlur</code> is <code>false</code>.</td></tr>
<tr><td><code>getCapabilities().backgroundSegmentationMask</code></td><td>not listed</td><td>Fake camera. <code>getSupportedConstraints().backgroundSegmentationMask</code> is <code>false</code>. A frame read with <code>MediaStreamTrackProcessor</code> had no keys in <code>metadata()</code>.</td></tr>
<tr><td>Mask route (<code>applyConstraints({ backgroundSegmentationMask: true })</code>, <code>MediaStreamTrackProcessor</code>, <code>metadata().backgroundSegmentationMask</code> uploaded with <code>texImage2D()</code>)</td><td>not verified</td><td>Written. It stops at the capability test here and the page says so, then draws the camera with nothing removed.</td></tr>
<tr><td>Chroma key shader on a canvas <code>captureStream()</code> video (green with a red box)</td><td>works</td><td>Key colour read from the frame's corner: rgb(0, 208, 0). Green showed the slide, rgb(0, 255, 255) and rgb(255, 212, 0). The box stayed rgb(255, 0, 0).</td></tr>
<tr><td>Chroma key on the fake camera</td><td>works</td><td>Key colour rgb(0, 135, 0) taken from the top left corner. The wall was removed. The wedge is a lighter green and came out partly transparent.</td></tr>
<tr><td>Difference key against a captured frame, wall of two colours</td><td>works</td><td>Before capture the wall is drawn. After it both colours showed the slide and a box that entered stayed red.</td></tr>
<tr><td>Difference key on the fake camera</td><td>works</td><td>After "Capture background" only the parts of the wedge that had moved were drawn.</td></tr></tbody></table>
<h3>Output</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>captureStream()</code> of the WebGL canvas through <code>RTCPeerConnection</code>, context made without <code>preserveDrawingBuffer</code></td><td>black frames</td><td>320×180 arrived, every sampled pixel rgb(0, 0, 0). The canvas is drawn only in its <code>paint</code> handler.</td></tr>
<tr><td>Same with <code>preserveDrawingBuffer: true</code></td><td>works</td><td>The slide's link arrived as rgb(9, 254, 250) and the presenter's box as rgb(255, 2, 0).</td></tr>
<tr><td>"Send as a camera" in the demo, WebGL route, fake camera with chroma key</td><td>works</td><td>640×360 received. 5 frames a second with software rendering.</td></tr>
<tr><td>"Record 5 s", <code>recordCanvas()</code></td><td>works</td><td>265 kB of <code>video/webm;codecs=vp9,opus</code>, 640×360.</td></tr>
<tr><td><code>paint</code> with the presenter video outside the canvas and no <code>requestPaint()</code></td><td>0 a second</td><td></td></tr>
<tr><td>Same with <code>requestPaint()</code> from <code>requestVideoFrameCallback()</code></td><td>30 a second</td><td></td></tr>
<tr><td>Video as a child of the slide, no <code>requestPaint()</code></td><td>30 a second</td><td></td></tr>
<tr><td>Paint rate of the demo, 2D route</td><td>29.5 a second</td><td>With and without the difference blend.</td></tr>
<tr><td>Paint rate of the demo, WebGL route</td><td>4.5 to 7 a second</td><td>Software GL. The shader takes 12 samples for the shadow and 12 more for three of the effects. Not a figure for a real GPU.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A WebGL canvas that draws only in <code>paint</code> gave black frames to <code>captureStream()</code>. <code>preserveDrawingBuffer: true</code> fixed it. The 2D canvas did not need anything.</li>
<li>After moving the layers to another canvas, the old canvas still got one <code>paint</code> and <code>drawElementImage()</code> threw. Guard with <code>layer.parentNode === canvas</code>.</li>
<li>Toggling an attribute to clear the hit-test cache raises a <code>paint</code>. Doing it in every paint would loop, so the page places the layers once for each shown size.</li>
<li>The alpha clip's disc moves, so a check cannot use a fixed point. The checks scan the canvas for a point that shows the video.</li>
<li>A <code>&lt;select&gt;</code> with a long option overflowed the 412 px row until its label got <code>min-width: 0</code>.</li>
<li>The bend effect displaces pixels by up to 27 px. Hit boxes stay where the elements are laid out.</li></ul>
<h3>Not verified</h3>
<ul><li>A real camera on a phone or laptop: what <code>getCapabilities()</code> lists for <code>backgroundBlur</code> and <code>backgroundSegmentationMask</code>, and the mask route end to end (including whether the mask is white on the person). The last live check and the line under the demo report the capabilities on the device. Picking "Camera, segmentation mask from the browser" runs the route.</li>
<li>Chroma and difference keys on a real room: lighting, auto exposure and camera noise. Pick the two camera sources on a device.</li>
<li>Hardware-decoded alpha video through <code>drawImage()</code> and <code>texImage2D()</code>. Live checks 1, 2 and 8 answer it on the device.</li>
<li>Frame rate of the shader on a phone GPU, and of the stream. "Send as a camera" prints the received frame rate.</li>
<li>Touch text selection (long press and handles) under the presenter.</li>
<li>WebGPU: no WebGPU route was built.</li>
<li>Whether the black <code>captureStream()</code> frames without <code>preserveDrawingBuffer</code> also happen with hardware GL.</li></ul>
<h3>Open ideas</h3>
<ul><li>A WebGPU route with <code>importExternalTexture(video)</code> for the presenter.</li>
<li>Move the hit boxes with the bend effect, by giving each control its own <code>drawable</code> element and transform.</li>
<li>A segmentation model in a worker (WebNN or WASM) as a fourth removal route for cameras with no mask.</li>
<li>Slide transitions from <code>/transitions/</code> with the presenter held above them.</li></ul>
<p><a href="https://html-in-canvas.page/presenter/">Open A video presenter over a slide made of DOM</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>What a canvas may not see</title>
<link>https://html-in-canvas.page/protected/</link>
<guid isPermaLink="true">https://html-in-canvas.page/protected/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>getImageData</category>
<category>&lt;geolocation&gt;</category>
<category>:visited</category>
<category>cross-origin</category>
<description>Permission buttons, visited links, spelling markers, autofill and content from other origins, each placed in a drawable canvas: is it in the picture, can script read it, and does it still work.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/protected/"><img src="https://html-in-canvas.page/protected/social.jpg" width="1200" height="630" alt="The page &quot;What a canvas may not see&quot;"></a></p>
<p><strong>Question:</strong> What does the browser do with protected content, such as permission buttons, visited links and cross-origin frames, when a canvas draws it?</p>
<p><strong>Short answer:</strong> Cross-origin content is left out of the picture and the canvas is never tainted. Permission elements are drawn and stop working. Links are drawn as unvisited.</p>
<p>
Some content is protected by the browser: permission buttons, the colour of visited links, spelling markers, autofill suggestions,
frames and images from other origins. I put each one in a <code>&lt;canvas content="drawable"&gt;</code> and the page measures three things:
whether it is in the picture, whether script can read its pixels, and whether it still works.
The table shows results recorded in the test browser. Press the button to measure this browser. Four cases need a person, and they're under "Try it by hand".
</p>
<h3>How it works</h3>
<p>
A drawable canvas lays out its children and paints them into a picture that <code>drawElementImage()</code> copies into the canvas.
The page can then read the canvas with <code>getImageData()</code>, or pass the element through a shader.
That would expose anything the browser paints but doesn't tell script about, so the browser has to do one of three things with protected content:
leave it out of the picture, paint a neutral version of it, or paint it and stop it working.
Each row above shows which.
</p>
<h3>Findings</h3>
<ul>
<li><b>The canvas is never tainted.</b> In Chromium 157 no case makes <code>getImageData()</code> or <code>toDataURL()</code> throw. Content the page may not read is left out of the picture: a cross-origin <code>&lt;iframe&gt;</code>, a cross-origin <code>&lt;img&gt;</code> or <code>&lt;video&gt;</code> loaded without CORS, and a cross-origin CSS background all draw 0 pixels. An image loaded with <code>crossorigin</code> from a server that allows it is drawn.</li>
<li><b>A shader gets the same picture.</b> <code>texElementSubImage2D()</code> of an element holding a cross-origin frame uploads a texture with the frame missing.</li>
<li><b>Permission elements are drawn and readable, and don't work.</b> <code>&lt;geolocation&gt;</code> reports <code>isValid</code> false with the reason <code>intersection_occluded_or_distorted</code> as soon as it is a canvas child, even when it's drawn exactly over its own box. A real click reaches it and opens no prompt. The same element outside a canvas is valid, and a click opens the prompt. To keep a permission button usable, position it over the canvas and don't make it a child.</li>
<li><b>Links are drawn as unvisited.</b> The picture uses the <code>:link</code> colour while the screen uses the <code>:visited</code> colour (recorded in Chromium 153 with a profile that keeps history).</li>
<li><b>System colours are readable, and they were before.</b> <code>AccentColor</code> and the others read back as the values <code>getComputedStyle()</code> reports.</li>
<li><b>Popovers and modal dialogs aren't in the picture.</b> The browser draws the top layer itself, above the canvas.</li>
<li><b>Open:</b> spelling markers and the autofill preview can't be produced by a script or by the test browser. They need the steps under "Try it by hand" on a real device. So does the system accent colour on a device where the person has changed it.</li>
<li><b>Chromium 157 crash:</b> calling <code>WEBGL_lose_context.loseContext()</code> on a drawable canvas and then removing the canvas crashes the tab. It happens at once when both are in one task, and after a wait too when the canvas has an <code>&lt;iframe&gt;</code> child. The WebGL row here keeps one context and doesn't release it.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/protected.md">findings/protected.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 and Chromium 153 on 2026-11-21 with real mouse clicks (<code>node tools/protected/record.mjs</code>, results in <code>public/protected/recorded.json</code>).</p>
<table><thead><tr><th>Content as a canvas child</th><th>In the picture</th><th>Notes</th></tr></thead><tbody><tr><td><code>&lt;iframe&gt;</code> from another origin</td><td>no</td><td>0 of 44,800 pixels. The same page from this origin draws all of them.</td></tr>
<tr><td><code>&lt;img&gt;</code>, <code>&lt;video&gt;</code> and CSS <code>background-image</code> from another origin, no CORS</td><td>no</td><td>0 pixels each. An <code>&lt;img crossorigin&gt;</code> from a server that allows it is drawn.</td></tr>
<tr><td>The same cross-origin frame through <code>texElementSubImage2D()</code></td><td>no</td><td><code>readPixels()</code> returns 0 non-transparent pixels.</td></tr>
<tr><td><code>&lt;geolocation&gt;</code>, <code>&lt;camera&gt;</code>, <code>&lt;microphone&gt;</code>, <code>&lt;usermedia&gt;</code></td><td>yes</td><td>Drawn and readable. <code>&lt;geolocation&gt;</code> reports <code>isValid</code> false, reason <code>intersection_occluded_or_distorted</code>, even drawn over its own box with no transform. A real click reaches the element and opens no prompt; the same click on the element outside a canvas opens it.</td></tr>
<tr><td>A visited link with a <code>:visited</code> colour</td><td>as unvisited</td><td>153 with history: 1,099 visited-colour pixels in a screenshot, 0 in the picture.</td></tr>
<tr><td>System colours, default accent colour on a checkbox</td><td>yes</td><td>The same values <code>getComputedStyle()</code> reports.</td></tr>
<tr><td>Password field</td><td>dots</td><td>Two passwords of the same length give identical pixels.</td></tr>
<tr><td>Open popover, modal <code>&lt;dialog&gt;</code></td><td>no</td><td>Drawn by the browser in the top layer, where they take the hit test.</td></tr></tbody></table>
<p>Things that bit:</p>
<ul><li>No case taints the canvas. <code>getImageData()</code> and <code>toDataURL()</code> never throw; the browser leaves the content out.</li>
<li><code>WEBGL_lose_context.loseContext()</code> on a drawable canvas that is then removed crashes the tab in 157: at once when both happen in one task, and after a 150 ms wait too when the canvas has an <code>&lt;iframe&gt;</code> child.</li>
<li>An open popover is positioned against the viewport, not the canvas. A hit test at canvas coordinates misses it unless the popover is placed over the canvas.</li>
<li>A link to the current page is only <code>:visited</code> if the page was reached by a link from the same site. A typed address does not count.</li>
<li>Not measurable in the test browsers: spelling markers (no dictionary), the autofill preview, a custom system accent colour, <code>&lt;install&gt;</code> (not present). The page has a canvas of live fixtures for these.</li></ul>
<p>Not verified:</p>
<ul><li>Spelling markers and the autofill preview in a drawn field, a tap on a permission element in a canvas on Android, and a custom system accent colour. "Try it by hand" on <code>/protected/</code> on a phone would verify them.</li>
<li>Latency and the long-frame split on real hardware, and whether <code>deviceTier()</code> matches the measured wall: the two latency buttons on <code>/perf/</code> (recorded in <code>findings/perf.md</code>).</li>
<li><code>showDirectoryPicker()</code> and <code>FileSystemObserver</code> on Android, a printed capture with its margin boxes, and HEVC recording: <code>/capture/</code> section C (recorded in <code>findings/capture.md</code>).</li></ul>
<p>For the index:</p>
<ul><li>Protected content: a drawable canvas is never tainted. A cross-origin iframe, and an image, video or CSS background loaded without CORS, are left out of the picture (0 pixels), in 2D and through <code>texElementSubImage2D()</code>. measured, C157 and C153, <code>/protected/</code>.</li>
<li>Protected content: a real click on a permission element in a canvas reaches it and opens no prompt; the same click outside a canvas opens it. measured, C157 and C153, <code>/protected/</code>.</li>
<li>Performance: Element Timing reports a canvas child even when the canvas never draws it; <code>presentationTime</code> is when the element's picture was painted. A 2D canvas shows a DOM change in the same frame as plain DOM. measured, C157, <code>/perf/</code>.</li></ul>
<p>Chromium bugs:</p>
<ul><li><code>WEBGL_lose_context.loseContext()</code> on an attached drawable WebGL canvas that is then removed crashes the renderer (C157).</li></ul>
<p><a href="https://html-in-canvas.page/protected/">Open What a canvas may not see</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A Qt Quick TextField backed by an &lt;input&gt;</title>
<link>https://html-in-canvas.page/qt-textfield/</link>
<guid isPermaLink="true">https://html-in-canvas.page/qt-textfield/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>A Qt Quick app with two kinds of text field that look the same: Qt's own TextField, and a QML component whose text, caret and selection are a real &lt;input&gt;. The page logs what the browser is given for each: keyboard hints, composition events and autofill attributes.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/qt-textfield/"><img src="https://html-in-canvas.page/qt-textfield/social.jpg" width="1200" height="630" alt="The page &quot;A Qt Quick TextField backed by an &lt;input&gt;&quot;"></a></p>
<p><strong>Question:</strong> Qt for WebAssembly takes all typing through one hidden input element. If a QML text field is a real drawn into Qt's scene instead, what do IME composition and autofill gain, and can the rest of the QML UI still bind to its text?</p>
<p><strong>Short answer:</strong> The binding works both ways. Qt's hidden input has an inputmode and no autocomplete or name, and sits at the corner of the window. The real input has both and sits at the field. A scripted composition deleted typed text in Qt's field. Autofill and a real IME on Android aren't verified.</p>
<p>
Qt for WebAssembly draws a <code>TextField</code> as pixels and takes typing through one hidden input element that it shares between all its fields.
This page loads a Qt Quick 6.10 app with three pairs of fields. In each pair the first is Qt's own <code>TextField</code>. The second is a QML component
with the same background and focus border, whose text, caret and selection are a real <code>&lt;input&gt;</code> drawn into Qt's scene.
Load the app, tap each field and type. The tables and logs under the app record what the browser was given for each field.
</p>
<h3>How it works</h3>
<p>
Qt Quick renders the window into one WebGL canvas, which Qt creates inside a shadow root. <code>DomItem</code> is a <code>QQuickItem</code> written for
<a href="https://html-in-canvas.page/native-ui/">/native-ui/</a>. It moves an element into that canvas, copies the element's picture into a texture with
<code>gl.texElementSubImage2D()</code> on each <code>paint</code> event, and passes the item's matrix to <code>canvas.updateElementGeometry()</code>, so the
browser's box for the element is where Qt drew it. The browser handles taps, keys, composition and autofill on the element as it does for any input.
</p>
<p>
<code>DomTextField.qml</code> is the Basic style's <code>TextField</code> background (a <code>Rectangle</code> with a 1 px border, 2 px in the highlight colour
when focused) with a <code>DomItem</code> inside it. The copy of <code>DomItem</code> on this page adds three things. Its <code>text</code> property reads
<code>element.value</code> on every <code>input</code> event and assigns it when QML writes the property. Its <code>domFocus</code> property follows the
element's <code>focus</code> and <code>blur</code> events. It handles the Tab key in the element by asking Qt for <code>nextItemInFocusChain()</code>, and it
focuses the element when Qt's own Tab reaches the item.
</p>
<p>
Qt's own <code>TextField</code> has no element where it is drawn. When one gets focus, Qt focuses a hidden
<code>&lt;input class="qt-window-input-element"&gt;</code> that it keeps at the top left corner of the window, and turns that element's events into Qt key and
input method events. The page's log listens in the capture phase on <code>window</code>, so it records the events for both kinds of field before Qt or
<code>DomItem</code> handle them.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The rest of the QML UI binds to the input like a <code>TextField</code>.</strong> <code>DomTextField.text</code> is a two-way property. A <code>Label</code> shows "Hello, " and the text, a <code>Button</code> is enabled when two fields aren't empty, and the button's handler clears a field by assigning <code>text</code>. All three work for both kinds of field. Measured in Chromium 157 on 2026-11-21.</li>
<li><strong>Qt gives the browser a keyboard hint and nothing for autofill.</strong> Qt 6.10.3 focuses one <code>&lt;input class="qt-window-input-element" type="text"&gt;</code> for every <code>TextField</code>. It sets <code>inputmode="email"</code> for <code>Qt.ImhEmailCharactersOnly</code>, <code>inputmode="numeric"</code> for <code>Qt.ImhDigitsOnly</code> and <code>type="password"</code> for <code>echoMode: TextInput.Password</code>. The element has no <code>autocomplete</code>, <code>name</code>, <code>id</code> or label, and QML's <code>TextField</code> has no property that would set one. The DOM fields have <code>type</code>, <code>name</code> and <code>autocomplete</code> (<code>email</code>, <code>current-password</code>, <code>one-time-code</code>).</li>
<li><strong>Not verified: whether Chrome on Android offers autofill for either field.</strong> Headless Chromium has no saved addresses, passwords or text messages. On the phone, tap each DOM field and each Qt field and look for a suggestion above the keyboard or a popup at the field. The log writes a line when an element starts to match <code>:autofill</code>.</li>
<li><strong>Qt's hidden input isn't at the field.</strong> Its box is 9 by 7 px at the top left corner of the Qt window for all three fields: 62, 207 and 354 px from the caret that Qt drew. The browser places an IME candidate window and an autofill popup from the focused element's box, and scrolls that box into view when the keyboard opens. A DOM field's box is 0 px from where Qt drew it.</li>
<li><strong>Composition events reach both fields, and Qt's <code>TextField</code> lost typed text.</strong> A composition sent with the DevTools protocol (<code>Input.imeSetComposition</code> with "に", "にほ", "にほん", then <code>Input.insertText</code> with "日本") fired the same <code>compositionstart</code>, <code>compositionupdate</code>, <code>beforeinput</code>, <code>input</code> and <code>compositionend</code> events on both elements. In an empty Qt field the result was "日本". In a Qt field that held "abcd" each update deleted typed characters: "bcd", "d", then nothing, and the field ended as "日本". The DOM field ended as "abcd日本". Not verified with a real IME.</li>
<li><strong>Qt's hidden input doesn't hold the field's text.</strong> After "abcd" was typed in a Qt field the hidden input's <code>value</code> was empty. During a composition it held only the composition string. So the keyboard isn't given the text around the caret.</li>
<li><strong>Text that is being composed is drawn in both fields.</strong> Qt draws its <code>preeditText</code> underlined and keeps <code>text</code> unchanged until the commit. The DOM field's <code>value</code> includes the composition string, so <code>DomTextField.text</code> and the label bound to it change during composition. The picture of the DOM field in Qt's scene had no composition underline.</li>
<li><strong>Qt's font has no Japanese glyphs.</strong> Qt drew "にほん" and "日本" as empty boxes with its bundled DejaVu Sans. The DOM field drew them with the browser's fallback font.</li>
<li><strong>A tap places the caret in both. Two taps select a word only in the DOM field.</strong> Scripted touch taps, Chromium 157. In the DOM field a tap past the end of the text didn't clear a selection of the whole value, which it does in a plain input outside a canvas. The cause wasn't identified.</li>
<li><strong>Tab walks all six fields in order, in both directions.</strong> <code>document.activeElement</code> is the shadow host. Inside the shadow root the active element alternates between Qt's hidden input and the DOM input. This needs the Tab handling in <code>DomItem</code>.</li>
<li><strong>Qt takes browser focus away unless stopped.</strong> When a Qt item that takes no text gets Qt's active focus, Qt 6.10.3 calls <code>focus()</code> on a hidden <code>div.qt-window-focus-helper</code>. That blurred the DOM input as soon as its <code>DomItem</code> took Qt's focus. <code>DomItem</code> replaces that element's <code>focus()</code> with a function that does nothing while a <code>DomItem</code> has Qt's focus.</li>
<li><strong>A stylesheet in Qt's shadow root styles the inputs.</strong> <code>start.js</code> appends a <code>&lt;link rel="stylesheet"&gt;</code> to the shadow root. <code>::placeholder</code> and <code>::selection</code> rules apply, which inline styles couldn't do.</li>
<li><strong>Cost: 23 MB.</strong> The WebAssembly file is 23.4 MB before compression, so the app loads after a tap.</li>
</ul>
<p>
Source: <a href="https://github.com/PaulKinlan/html-in-canvas-demos/tree/main/native/qt-textfield">native/qt-textfield</a>.
The binary is statically linked against the open-source edition of Qt 6.10.3 (LGPL-3.0 and GPL-3.0). Its complete source is that folder plus Qt from download.qt.io.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/qt-textfield.md">findings/qt-textfield.md</a> in the repository.</p>
<p>Measured in C157 (headless Chromium 157.0.8103.78, 2.625 device scale, 412 px wide, touch) on 2026-11-21, by Playwright scripts and by the page's live checks. Qt Quick 6.10.3 for WebAssembly (single thread, Basic style, WebGL2), Emscripten 4.0.7. Source in <code>native/qt-textfield/</code>. The build is 23.4 MB of WebAssembly (22.3 MiB) and 264 KB of JavaScript, loaded after a tap. PLAN.md backlog item 27.1.</p>
<p>The app has three pairs of fields: email, password and a code from a text message. In each pair the first is Qt's <code>TextField</code> and the second is <code>DomTextField.qml</code>, which is the Basic style's background with a <code>DomItem</code> holding a real <code>&lt;input&gt;</code>. Nothing on this page was run on a phone. The page writes its event log and its tables from real events so that the same measurements can be read on the phone.</p>
<h3>What the browser is given</h3>
<table><thead><tr><th>Question</th><th>Qt <code>TextField</code></th><th><code>DomTextField</code></th></tr></thead><tbody><tr><td>Element that has focus</td><td>One <code>&lt;input class="qt-window-input-element" contenteditable="true" type="text"&gt;</code> for all three fields, in Qt's shadow root, a child of <code>div.qt-window</code></td><td>The field's own <code>&lt;input&gt;</code>, a child of <code>canvas.qt-window-canvas</code> in the same shadow root</td></tr>
<tr><td><code>document.activeElement</code></td><td><code>div#qt-shadow-container</code> (the shadow host). <code>shadowRoot.activeElement</code> is the hidden input</td><td>The same host. <code>shadowRoot.activeElement</code> is the field's input</td></tr>
<tr><td><code>type</code></td><td><code>text</code>. <code>password</code> when <code>echoMode</code> is <code>TextInput.Password</code></td><td><code>email</code>, <code>password</code>, <code>text</code></td></tr>
<tr><td><code>inputmode</code></td><td><code>email</code> for <code>Qt.ImhEmailCharactersOnly</code>, <code>numeric</code> for <code>Qt.ImhDigitsOnly</code>, <code>text</code> for the password field</td><td>not set, not set, <code>numeric</code></td></tr>
<tr><td><code>autocomplete</code>, <code>name</code>, <code>id</code>, label</td><td>none of them. QML's <code>TextField</code> has no property for them</td><td><code>email</code>, <code>current-password</code>, <code>one-time-code</code>; <code>name</code> and <code>aria-label</code> set</td></tr>
<tr><td><code>autocapitalize</code>, <code>enterkeyhint</code></td><td>not set</td><td>as written in the markup (<code>autocapitalize="none"</code> on email, <code>enterkeyhint="done"</code> on the code field)</td></tr>
<tr><td><code>&lt;form&gt;</code></td><td>none</td><td>none</td></tr>
<tr><td>Box of the focused element</td><td>9 by 7 px at the top left corner of the Qt window, for every field</td><td>352 by 36 px, the field</td></tr>
<tr><td>Distance from that box to where Qt drew the caret or the field</td><td>62 px (email), 207 px (password), 354 px (code)</td><td>0 px</td></tr>
<tr><td>A point on the field hits</td><td>the canvas</td><td>the input</td></tr>
<tr><td><code>value</code> of the focused element</td><td>empty after "abcd" was typed. During a composition it holds the composition string only</td><td>the field's text</td></tr></tbody></table>
<h3>Typing, composition, selection, focus</h3>
<p>Composition was sent through the DevTools protocol: <code>Input.imeSetComposition</code> with "に", "にほ" and "にほん", then <code>Input.insertText</code> with "日本". This goes through the browser's input method path and fires composition events. It is not a real IME.</p>
<table><thead><tr><th>Experiment</th><th>Qt <code>TextField</code></th><th><code>DomTextField</code></th></tr></thead><tbody><tr><td>Key presses "ab"</td><td><code>keydown</code> on the hidden input, no <code>beforeinput</code> or <code>input</code> logged. <code>TextField.text</code> is "ab"</td><td><code>keydown</code>, <code>beforeinput</code> and <code>input</code> (<code>insertText</code>) per key. <code>DomTextField.text</code> is "ab"</td></tr>
<tr><td>Events during the composition</td><td><code>compositionstart</code>, then <code>compositionupdate</code>, <code>beforeinput</code> and <code>input</code> (<code>insertCompositionText</code>, <code>isComposing</code> true) for each update, then <code>compositionend</code></td><td>the same events</td></tr>
<tr><td>Composition in an empty field</td><td><code>preeditText</code> is "にほん", <code>text</code> stays empty until the commit, then "日本"</td><td><code>value</code> and <code>DomTextField.text</code> are "に", "にほ", "にほん", then "日本"</td></tr>
<tr><td>Composition in a field that holds "abcd"</td><td><strong>text is lost.</strong> After each update <code>text</code> was "bcd", "d", then empty. Final text "日本". With one update and a commit of "日" the field ended as "cd日". The same on a fresh page load and in the code field ("1234" became "34日")</td><td>"abcdに", "abcdにほ", "abcdにほん", final "abcd日本"</td></tr>
<tr><td>Uncommitted text in Qt's pixels</td><td>drawn, underlined, as three empty boxes: Qt's bundled DejaVu Sans has no Japanese glyphs</td><td>drawn with the browser's fallback font. No composition underline in the picture (seen in a screenshot)</td></tr>
<tr><td>A QML binding on <code>text</code> during composition</td><td>does not change until the commit</td><td>changes on every update: the label read "Hello, にほん"</td></tr>
<tr><td><code>page.keyboard.insertText("xy")</code></td><td><code>beforeinput</code> and <code>input</code> (<code>insertText</code>), text "xy"</td><td>the same</td></tr>
<tr><td>Arrow keys, Backspace, Shift+Arrow selection, typing over a selection</td><td>works</td><td>works</td></tr>
<tr><td>Control+A</td><td>selects all, drawn in the highlight colour</td><td>selects all, drawn with the <code>::selection</code> rule from the stylesheet in the shadow root</td></tr>
<tr><td>Tap inside the text places the caret</td><td>yes ("hel|lo world")</td><td>yes ("hel|lo world")</td></tr>
<tr><td>Two taps on a word</td><td>no selection. The next key was inserted at the caret</td><td>the word is selected. The next key replaced it</td></tr>
<tr><td>Tap past the end of the text while everything is selected, then type "Z"</td><td>selection cleared, "Z" appended</td><td>selection kept, "Z" replaced everything. A plain <code>&lt;input type="email"&gt;</code> outside a canvas, same steps, cleared the selection. Cause not identified</td></tr>
<tr><td>Caret drawn</td><td>by Qt</td><td>by the browser, in the element's picture. It blinks in Qt's pixels</td></tr>
<tr><td>Tab through the six fields, and Shift+Tab back</td><td>Qt's own focus chain</td><td>needs the bridge: <code>DomItem</code> handles the Tab <code>keydown</code>, calls <code>nextItemInFocusChain()</code>, and focuses the element when Qt's Tab reaches the item. With it, 9 Tab presses and 6 Shift+Tab presses visited the fields in layout order, wrapping at the end</td></tr>
<tr><td>Tap on an empty part of the Qt window while a field has focus</td><td>the hidden input keeps focus</td><td>the input keeps focus</td></tr>
<tr><td>QML reads and writes <code>text</code></td><td><code>Label</code> and <code>Button</code> bindings work</td><td>the same bindings work. <code>domCode.text = ""</code> in a button handler emptied the input</td></tr>
<tr><td>The focus border</td><td><code>activeFocus</code></td><td><code>DomItem.domFocus</code>, set from the element's <code>focus</code> and <code>blur</code> events</td></tr></tbody></table>
<h3>Live checks on the page</h3>
<p>10 checks, on a second copy of the app in a frame opened with <code>?nofocus</code>, where <code>HTMLElement.prototype.focus</code> records the call and does not run it. 8 pass. 2 fail and are marked as expected: "Qt's hidden input has an autocomplete or a name attribute" and "Qt's hidden input is at the caret of the focused TextField" (354 px away in the frame).</p>
<p><code>npm run check:jank -- /qt-textfield/</code>: cls 0, scroll 0, focus 0, 0 WebGL contexts before the tap. With <code>--checks</code>: the same, focus 0.</p>
<h3>Things that bit</h3>
<ul><li>Qt 6.10.3 calls <code>focus()</code> on a hidden <code>div.qt-window-focus-helper</code> whenever a Qt item that takes no text gets Qt's active focus. The <code>DomItem</code> takes Qt's active focus when its element is focused (so that a Qt <code>TextField</code> drops its caret), and Qt then blurred the element at once. <code>DomItem</code> replaces <code>focus</code> on that one element with a function that does nothing while a <code>DomItem</code> has Qt's active focus. In the measured session it stopped 16 calls.</li>
<li><code>focusin</code> and <code>focusout</code> between two elements of one shadow root do not leave the shadow root. A listener on <code>window</code> saw none of them. The log listens on the shadow root.</li>
<li><code>&lt;input type="email"&gt;</code> has no <code>selectionStart</code>. The caret measurements type a marker character and read the value.</li>
<li>Playwright hides the caret in screenshots by default. <code>caret: 'initial'</code> shows that the browser's caret is in the element's picture.</li>
<li>Page styles do not reach Qt's shadow root. Instead of copying computed styles inline, <code>start.js</code> appends a <code>&lt;link rel="stylesheet"&gt;</code> to the shadow root, so <code>::placeholder</code>, <code>::selection</code> and <code>:autofill</code> rules apply.</li>
<li>The <code>??=</code> operator inside <code>EM_JS</code> is read as a trigraph by the C preprocessor and gives a warning.</li></ul>
<h3>Not verified</h3>
<p>All of these need Chrome on an Android phone. Open <code>/qt-textfield/</code>, tap "Load the Qt app", do the step, then tap "Copy the log" and send the text.</p>
<ul><li><strong>Autofill.</strong> Headless Chromium has no saved data, so no field was ever autofilled and <code>:autofill</code> never matched. On the phone, with a saved email address and a saved password for the site: tap the DOM email field, then the DOM password field, and note whether Chrome shows a suggestion above the keyboard or the password manager's sheet. Do the same for the two Qt fields. The log writes "now matches :autofill" when a value is filled in. Also not known: whether Chrome's autofill considers an input that is a child of a canvas inside a shadow root with no <code>&lt;form&gt;</code>, and whether its popup is placed at the box set by <code>updateElementGeometry()</code>.</li>
<li><strong>One-time codes.</strong> Tap the DOM code field after a text message with a code arrives and note whether the keyboard offers it. <code>autocomplete="one-time-code"</code> is on the DOM field only.</li>
<li><strong>The keyboard that opens.</strong> Note for each field which keyboard appears (email layout, digits). The table above gives the attributes; the keyboard itself was not seen. The <code>visualViewport</code> lines in the log show the height change.</li>
<li><strong>A real IME.</strong> With a Japanese, Chinese or Korean keyboard: type a few Latin letters in the Qt email field, then compose a word, and see whether the letters survive. Do the same in the DOM field. The scripted composition deleted them in the Qt field. Note where the candidate window appears for each field: Qt's hidden input is at the top left corner of the Qt window, the DOM input is at the field.</li>
<li><strong>Scroll into view.</strong> Tap the lowest Qt field and the lowest DOM field with the keyboard closed and note whether the field stays visible above the keyboard. Chrome scrolls the focused element's box, which for Qt's fields is the window corner.</li>
<li><strong>Touch selection.</strong> Long-press a word in each field. Selection handles, the cut and paste menu and the magnifier were not seen in headless Chromium. Two scripted taps selected a word in the DOM field only.</li>
<li><strong>Fonts.</strong> The stylesheet asks for "DejaVu Sans", which is installed on the test machine and is Qt's bundled font, so the two fields matched there. Android has no DejaVu Sans, so the DOM field will fall back to the system font and the two fields will differ. Not seen.</li>
<li><strong>The "next" key of the keyboard.</strong> Whether it moves from a DOM field to the Qt field after it. The Tab bridge handles a <code>Tab</code> key event only.</li>
<li><strong>A lost WebGL context.</strong> The page shows a message on <code>webglcontextlost</code>. The event was not forced.</li>
<li><strong>A screen reader.</strong> The DOM inputs have <code>aria-label</code>, but Qt sets <code>aria-hidden="true"</code> on its canvas, which is their parent. Whether a screen reader reaches them was not tested.</li>
<li>The tap that does not clear a full selection in the DOM field: whether it happens with a finger, and why.</li></ul>
<h3>Open ideas</h3>
<ul><li>Give Qt's own hidden input an <code>autocomplete</code> and a <code>name</code> from the page when a given <code>TextField</code> has focus, and move its box to the caret with CSS, to see how much of the gap closes without replacing the field.</li>
<li>Wrap the DOM fields in a <code>&lt;form&gt;</code> inside the canvas with a submit button, for password managers that save on submit.</li>
<li>Report the composition result to the Qt project if a real IME shows the same loss of text.</li></ul>
<p><a href="https://html-in-canvas.page/qt-textfield/">Open A Qt Quick TextField backed by an &lt;input&gt;</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>DOM elements in a Qt Widgets window</title>
<link>https://html-in-canvas.page/qt-widgets-dom/</link>
<guid isPermaLink="true">https://html-in-canvas.page/qt-widgets-dom/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>drawElementImage</category>
<category>2D canvas</category>
<description>A Qt Widgets app paints with Qt's raster engine and copies the result to a 2D canvas. Real &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elements are drawn into that canvas with drawElementImage() after each flush.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/qt-widgets-dom/"><img src="https://html-in-canvas.page/qt-widgets-dom/social.jpg" width="1200" height="630" alt="The page &quot;DOM elements in a Qt Widgets window&quot;"></a></p>
<p><strong>Question:</strong> Qt Widgets windows are painted in software and copied to a 2D canvas with putImageData(). Can drawElementImage() after each copy put live DOM elements in such a window?</p>
<p><strong>Short answer:</strong> Yes. The page wraps putImageData() on Qt's canvas and draws the elements after it. In a 2D canvas the draw also sets the hit box, so no geometry call is needed.</p>
<p>
Qt Quick renders with WebGL, and <a href="https://html-in-canvas.page/native-ui/">an earlier page</a> gave it DOM elements as textures. Qt Widgets, the older and more
widely used Qt toolkit, paints every window in software and copies the changed pixels to a 2D canvas with <code>putImageData()</code>.
This page loads a Qt Widgets 6.10 app and draws real elements into the window's canvas with <code>drawElementImage()</code> after each of
those copies. Load the app, then tap a field to type, scroll the window, move the slider, or open the Qt combo box above the fields.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Yes, with one wrapped method.</strong> Qt for WebAssembly paints a Qt Widgets window with its raster engine and copies the changed rectangles to a 2D canvas with <code>putImageData()</code>. The page wraps <code>putImageData()</code> on that canvas's context and calls <code>drawElementImage()</code> for each element straight after it. Qt 6.10.3 is unchanged. Measured in Chromium 157.</li>
<li><strong>No geometry call is needed.</strong> In a 2D canvas <code>drawElementImage()</code> also sets the hit box, so a tap lands on the field where Qt laid out its widget. An element whose widget is scrolled out isn't drawn and is made <code>inert</code>.</li>
<li><strong>The canvas is Qt's, inside a shadow root.</strong> Qt creates <code>canvas.qt-window-canvas</code> in the shadow root of a child of the container. The page adds the <code>layoutsubtree</code> and <code>content="drawable"</code> attributes after Qt made it and appends the elements to it. Styles from the page don't reach the shadow root, so the page copies each element's computed style inline first.</li>
<li><strong>Layout goes both ways through <code>heightForWidth()</code>.</strong> Qt's layout gives the widget a width in <code>resizeEvent()</code>, the element takes that width, and the widget answers <code>heightForWidth()</code> with the element's <code>offsetHeight</code>.</li>
<li><strong>A Qt popup covers the fields with no guard code.</strong> The <code>QComboBox</code> list is a second Qt window, which is a second canvas above the first one, so the browser's own hit testing gives the popup the tap.</li>
<li><strong>Drawing after the flush doesn't loop.</strong> <code>drawElementImage()</code> outside a paint event doesn't cause a paint event. A change in an element fires <code>paint</code>, the widget calls <code>update()</code>, Qt flushes and the elements are drawn again: one paint event, two flushes.</li>
<li><strong>Qt overwrites the element on every flush of its rectangle.</strong> The widget fills its background in <code>paintEvent()</code>, so the element has to be drawn again after every flush. The page draws all of them after each one.</li>
<li><strong>Touch scrolling is Qt's, and stops at an element.</strong> <code>QScroller::grabGesture()</code> on the viewport makes a touch drag scroll the area. A drag that starts on a DOM element doesn't scroll it, because the element stops the event before Qt's listeners.</li>
<li><strong>Cost: 14 MB.</strong> The WebAssembly file is 14.1 MB before compression, so the app loads after a tap on this page.</li>
</ul>
<p>
Source: <a href="https://github.com/PaulKinlan/html-in-canvas-demos/tree/main/native/qt-widgets-dom">native/qt-widgets-dom</a>.
The binary is statically linked against the open-source edition of Qt 6.10.3 (LGPL-3.0 and GPL-3.0). Its complete source is that folder plus Qt from download.qt.io.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/qt-widgets-dom.md">findings/qt-widgets-dom.md</a> in the repository.</p>
<p>Measured in C157 (headless, 2.625 device scale, touch) on 2026-11-21. Qt 6.10.3 for WebAssembly (single thread), Fusion style, Emscripten 4.0.7. Source in <code>native/qt-widgets-dom/</code>. The build is 14.1 MB of WebAssembly and 230 KB of JavaScript, loaded after a tap.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Draw DOM elements into a Qt Widgets window after Qt's flush</td><td>works</td><td>Qt copies its raster buffer with <code>putImageData()</code> on a 2D context. The page wraps that method on Qt's context and calls <code>drawElementImage()</code> after it. Text pixels of the textarea are read back from Qt's canvas.</td></tr>
<tr><td>Make Qt's own canvas drawable after Qt created it</td><td>works</td><td><code>canvas.qt-window-canvas</code> is in the shadow root of <code>#qt-shadow-container</code>. Setting <code>layoutsubtree</code> and <code>content="drawable"</code> and appending the elements later is enough.</td></tr>
<tr><td>Hit testing where Qt laid out the widget</td><td>works</td><td>No <code>updateElementGeometry()</code>: the 2D draw sets the hit box. <code>elementFromPoint()</code> on the shadow root returns the input.</td></tr>
<tr><td>Layout both ways</td><td>works</td><td><code>resizeEvent()</code> sets the element width, <code>heightForWidth()</code> returns <code>offsetHeight</code>.</td></tr>
<tr><td>A change in an element repaints the widget</td><td>works</td><td>1 paint event, 2 flushes, 8 element draws for one changed textarea value.</td></tr>
<tr><td>Drawing after a flush causes no paint events</td><td>works</td><td>0 paint events in 60 idle animation frames. In the check fixture Qt flushed twice in those frames; on the page it flushed 0 times in 3 s. The cause of the two was not identified (a blinking <code>QLineEdit</code> caret is the likely one).</td></tr>
<tr><td>A field scrolled out of the <code>QScrollArea</code></td><td>works</td><td><code>visibleRegion()</code> is empty, the element is not drawn and is <code>inert</code>. It returns when scrolled back.</td></tr>
<tr><td>A <code>QComboBox</code> popup over the fields</td><td>works, no guard</td><td>The popup is a second Qt window canvas above the first. The point over the email field hits that canvas.</td></tr>
<tr><td>Opacity from a <code>QSlider</code></td><td>works</td><td><code>globalAlpha</code> for the draw. Touch drag on the slider set 0.52.</td></tr>
<tr><td>Touch: tap a field and type, drag the slider, open the combo, scroll by dragging on Qt content</td><td>works</td><td>Scrolling needs <code>QScroller::grabGesture(viewport, TouchGesture)</code>.</td></tr>
<tr><td>Touch drag that starts on a DOM element scrolls the Qt area</td><td>does not</td><td>The element stops pointer events before Qt's listeners, so Qt never sees the drag.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The canvas is not in <code>container.shadowRoot</code>. Qt adds a child <code>#qt-shadow-container</code> and attaches the shadow root to that.</li>
<li>Page styles do not reach elements moved into Qt's shadow root. <code>start.js</code> copies computed styles inline before the move.</li>
<li>A <code>sizeHint()</code> that laid the element out at a default width alternated with the real width and made a paint and flush loop at frame rate. The width is set only in <code>resizeEvent()</code>.</li>
<li>Scrolling a <code>QScrollArea</code> moves the content widget, not its children, so no <code>moveEvent()</code> reaches the DomWidget. The scroll bar's <code>valueChanged</code> is connected to <code>DomWidget::sync()</code>.</li>
<li>With no context of its own the page holds no WebGL context: Qt Widgets uses 2D canvases only.</li></ul>
<h3>Not verified</h3>
<ul><li>A real phone (A159): the keyboard, the native select picker over Qt's canvas, IME, and the time to compile 14 MB.</li>
<li>The hit box of a field that is half scrolled out. The draw is clipped to the visible part; whether the hit box is clipped too was not measured.</li>
<li>A mouse drag on the <code>QSlider</code> in a browser context with touch emulation did not move it in one scripted run. Not investigated.</li>
<li>Screen readers. The DOM fields have names; Qt's widgets have no DOM nodes unless Qt's accessibility is switched on, which this page does not do.</li>
<li>A lost 2D context. The page shows a message on <code>contextlost</code>; the event was not forced.</li>
<li>Qt's threaded build and Qt Widgets with an OpenGL window.</li></ul>
<p><a href="https://html-in-canvas.page/qt-widgets-dom/">Open DOM elements in a Qt Widgets window</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Redacting selected text</title>
<link>https://html-in-canvas.page/redact/</link>
<guid isPermaLink="true">https://html-in-canvas.page/redact/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Range.getClientRects()</category>
<category>CSS Custom Highlight</category>
<category>ctx.filter</category>
<description>Select part of a letter and the canvas covers it with a bar, large pixels, a blur or changing letters. A table shows where the covered text can still be read (the DOM, copy) until it's removed from the DOM as well.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/redact/"><img src="https://html-in-canvas.page/redact/social.jpg" width="1200" height="630" alt="The page &quot;Redacting selected text&quot;"></a></p>
<p><strong>Question:</strong> What does a redaction drawn by a canvas hide, and what still holds the text?</p>
<p><strong>Short answer:</strong> It hides pixels only. The DOM, copy and anything that reads the DOM still have the text.</p>
<p>
A letter drawn by a canvas. Select part of it and press “Redact selection”, or let the page find the numbers and the email address. The canvas covers those ranges with a bar, large pixels, a blur or changing letters. The table under the letter shows where the covered text can still be read.
</p>
<h3>How it works</h3>
<p>
“Redact selection” stores the selection as two character offsets and adds a <code>Range</code> for it to a CSS Custom Highlight with no <code>::highlight()</code> rule. The element reads the rectangles of that Highlight's ranges and the effect draws over them after it has drawn the text. The drawing is only pixels. The characters stay in the DOM, so anything that reads the DOM still gets them: copy, <code>textContent</code>, find-in-page, a screen reader. “Remove the text from the DOM” replaces each redacted character with a block character, after which the canvas bar covers blocks.
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.</p>
<ul>
<li><strong>A bar drawn after the element covers every pixel of the range</strong> in the canvas and in a PNG made from it (checked below, pixel by pixel).</li>
<li><strong>The canvas hides nothing from the DOM.</strong> After a redaction, <code>textContent</code>, <code>Range.toString()</code> and copy return the covered text. A canvas redaction is only safe as an exported picture, or together with removing the text.</li>
<li><strong>Pixels and blur are made from the text's own pixels</strong>, so they keep some information about it: length, word gaps and rough letter shapes. The bar keeps only the length. Changing letters keeps the length and the font.</li>
<li><strong><code>ctx.filter</code> applies to <code>drawElementImage()</code>.</strong> The blur style is the element drawn a second time through a <code>blur()</code> filter and a clip.</li>
<li><strong>A canvas can be the source of its own <code>drawImage()</code></strong> after <code>drawElementImage()</code>. The pixel style reads the part of the canvas it is about to replace. The canvas isn't tainted by same-origin element content, so PNG export works. The page reads pixels only from a <code>drawImage()</code> copy of the canvas.</li>
<li><strong>Replacing characters in the DOM changes line breaks</strong> when the block character is wider than the letters it replaces. The offsets stay valid because the number of characters doesn't change.</li>
</ul>
<p><strong>Not verified:</strong> what find-in-page and TalkBack report for a redacted range (both read the DOM, so the expected answer is the original text until it's removed), and selecting by touch on a phone.</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/selection.md">findings/selection.md</a> in the repository.</p>
<h3>Five pages drawn from ranges (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>, <code>/redact/</code>, <code>/selection-heat/</code>, <code>/share-card/</code>)</h3>
<p>Measured in headless Chromium 157 (Linux, software renderer, device scale factor 2) on 2026-11-21. Each row is a live check on the page named. The first four pages are 2D effects registered on <code>&lt;selection-fx&gt;</code> with <code>defineSelectionEffect()</code> from their own modules. Shared helpers are in <code>lib/selection-tools.js</code> and shared styles in <code>lib/selection-article.css</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Rectangles of a range that is not selected (<code>/selection-peers/</code>)</td><td>works</td><td><code>Range.getClientRects()</code> needs no selection. A canvas draws any number of other readers' ranges with no change to the DOM or to the document's selection (HTML and selection compared before and after).</td></tr>
<tr><td>A selection sent as two offsets into <code>textContent</code> and rebuilt in another document</td><td>works</td><td>Round trip checked across an inline element. A message on a <code>BroadcastChannel</code> arrived in 25 ms and the range was drawn 48.2 px wide for 4 characters of 12 px.</td></tr>
<tr><td>A same-origin frame as a second reader</td><td>works</td><td>Each document has its own selection, so selecting in the frame does not clear the page's selection. Checked with a script, not a live check: both selections were held at once and each side drew the other's range.</td></tr>
<tr><td>One <code>Range</code> per character (<code>/selection-glyphs/</code>)</td><td>works</td><td>12 rectangles for 12 letters, each 12.0 px wide in a 20 px monospace font. The box is the advance width and the line's text height, not the ink.</td></tr>
<tr><td>Letters taken out of the element's picture with an even-odd clip and drawn elsewhere</td><td>works</td><td>After dropping 12 letters: 0 ink pixels on their line, 3047 under it, <code>textContent</code> unchanged.</td></tr>
<tr><td>The canvas outside the element's ink</td><td>transparent</td><td>An element with no background leaves the canvas transparent between glyphs, so a piece of the canvas is a letter with nothing behind it.</td></tr>
<tr><td>288 letters per frame from a snapshot (<code>drawImage()</code>) against from the live element (<code>drawElementImage()</code> through a clip, once per letter)</td><td>49.6 ms against 442.3 ms</td><td>Software renderer, and both numbers include <code>getImageData()</code> of the whole canvas. The live route replays the element's paint record once per letter.</td></tr>
<tr><td>A bar drawn over a range after the element (<code>/redact/</code>)</td><td>covers every pixel</td><td>10560 canvas pixels inside the range's rectangle, all the bar colour.</td></tr>
<tr><td>The DOM after a canvas redaction</td><td>still has the text</td><td><code>textContent</code>, <code>Range.toString()</code> and copy return it. The page's copy handler and "Remove the text from the DOM" are the two ways it offers to close that.</td></tr>
<tr><td><code>ctx.filter = 'blur()'</code> on <code>drawElementImage()</code></td><td>works</td><td>The blur style changed 9196 pixels inside the range and 0 outside. Filter lengths are canvas pixels, so the page multiplies by the canvas scale.</td></tr>
<tr><td><code>drawImage(canvas)</code> with the canvas itself as the source, after <code>drawElementImage()</code></td><td>works</td><td>The pixel style reads the part of the canvas it replaces. The canvas is not tainted by same-origin element content.</td></tr>
<tr><td>Replacing characters in the DOM under a Custom Highlight range</td><td>offsets stay valid</td><td>Setting <code>node.data</code> collapses live ranges in that node, so the page rebuilds its ranges from stored offsets. 10 characters replaced, the range kept one rectangle.</td></tr>
<tr><td>One element drawn twice in a frame at different sizes (<code>/selection-heat/</code>)</td><td>works</td><td>The minimap is the article at scale 0.169 in the fixture: 478 text pixels and 57 heat pixels at the scaled position.</td></tr>
<tr><td>A minimap in a second canvas</td><td>not possible</td><td>An element is drawn only by its own canvas (known from the first findings), so the minimap is inside the article's canvas, in a column the article reserves with padding.</td></tr>
<tr><td><code>document.caretPositionFromPoint()</code> on text drawn by the canvas</td><td>works</td><td>Returned offset 7 for a point on the eighth character.</td></tr>
<tr><td>An element drawn at four times its layout size (<code>/share-card/</code>)</td><td>drawn again, not stretched</td><td>A 1 px line became 4 black pixels with 0 grey pixels beside it.</td></tr>
<tr><td><code>canvas.toBlob()</code> after <code>drawElementImage()</code></td><td>works</td><td>PNGs of 1200×630, 1080×1080 and 1080×1920 decoded at those sizes.</td></tr>
<tr><td><code>scrollHeight</code> and <code>clientHeight</code> on a canvas child</td><td>work</td><td>They drive the card's type size: 67.5 px for 3 words, smaller for 420 characters, both fit.</td></tr>
<tr><td>A canvas child wider than the canvas element</td><td>works</td><td>The figure is 600 px wide in a canvas shown about 396 px wide. The picture is complete.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li><code>shared/style.css</code> gives <code>figure</code> a <code>max-width: 100%</code>, and a canvas child obeys it against the canvas's CSS width. The share card was laid out 396 px wide and drawn stretched until the figure got <code>max-width: none</code>.</li>
<li>After a 2D <code>drawElementImage()</code> with a size different from the layout size, <code>getBoundingClientRect()</code> of the element reports the drawn size (396×208 for a 600×315 figure). Layout sizes come from <code>offsetWidth</code> and <code>clientHeight</code>.</li>
<li><code>s.rects</code> in a <code>&lt;selection-fx&gt;</code> effect holds the selection and the <code>highlight</code> attribute's ranges together. An effect that draws the two differently reads <code>s.marked</code> for the ranges and uses <code>s.rects</code> only while something is selected.</li>
<li>Fitting type by <code>scrollHeight</code> and then changing <code>line-height</code> undoes the fit. The line height is fixed in CSS.</li>
<li>Reported from Paul's phone (Android Chrome 159) through the coordinator on 2026-11-21, not measured here: a drawable 2D canvas that is read back with <code>getImageData()</code> (with <code>willReadFrequently</code>) lost every 2D context on the page. These five pages never call <code>getImageData()</code> on a drawable canvas. <code>snapshot()</code> and <code>copyCanvas()</code> in <code>lib/selection-tools.js</code> copy the canvas to an <code>OffscreenCanvas</code> with <code>drawImage()</code> and read the copy.</li>
<li>The site menu stays at the top of the window, so a minimap that follows the scroll is placed 64 px below the window's top edge.</li>
<li>The article's own minimap column is part of the element, so the minimap shows an empty strip at its right edge.</li></ul>
<h4>Not verified</h4>
<ul><li>Touch on all five pages: long-press selection, the Android handles, the automatic drop 0.7 s after the last selection change on <code>/selection-glyphs/</code>, and dragging in the minimap column on <code>/selection-heat/</code>. Needs a phone.</li>
<li>Frame rate with several hundred loose letters, and how closely the minimap follows a touch scroll. Needs a phone.</li>
<li><code>navigator.share()</code> with a PNG file and <code>navigator.clipboard.write()</code> with a PNG on <code>/share-card/</code>. The headless browser has no share sheet and no clipboard permission. Press Share and Copy picture on a phone.</li>
<li>What find-in-page and TalkBack report for a range covered on <code>/redact/</code>. Both read the DOM, so the expected answer is the original text until it is removed.</li>
<li>Two people on two devices on <code>/selection-peers/</code>. The page has a <code>BroadcastChannel</code> only, so it reaches tabs and frames of one browser. A relay server would carry the same message.</li></ul>
<h4>Ideas not built</h4>
<ul><li>A relay (Durable Object or WebRTC data channel) so <code>/selection-peers/</code> works between devices, and readers' carets as well as selections.</li>
<li>Letters on <code>/selection-glyphs/</code> that collide with each other and can be pushed with a finger.</li>
<li>Redaction that also exports a PDF, and a "peek" that shows a range while it is pressed.</li>
<li>Heat collected from real visitors, and a minimap for a whole page of several canvases.</li>
<li>Share cards with a QR code of a text-fragment link to the passage.</li></ul>
<h4>For the index</h4>
<ul><li>Text and ranges: any <code>Range</code> has rectangles at the drawn position whether or not it is selected; one <code>Range</code> per character gives per-letter boxes (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: <code>ctx.filter</code>, <code>clip('evenodd')</code> and a self-sourced <code>drawImage()</code> all apply to <code>drawElementImage()</code> output (<code>/redact/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: an element drawn larger than its layout is re-rasterised, and one element can be drawn several times per frame at different sizes (<code>/share-card/</code>, <code>/selection-heat/</code>).</li>
<li>Export: <code>toBlob()</code> and <code>getImageData()</code> work after <code>drawElementImage()</code> of same-origin content (<code>/share-card/</code>, <code>/redact/</code>).</li>
<li>Layout: <code>scrollHeight</code> works on canvas children; <code>max-width: 100%</code> on a canvas child resolves against the canvas's CSS width (<code>/share-card/</code>).</li>
<li>Accessibility and privacy: drawing over text in the canvas hides nothing from the DOM (<code>/redact/</code>).</li></ul>
<p><a href="https://html-in-canvas.page/redact/">Open Redacting selected text</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>View transitions drawn by a canvas</title>
<link>https://html-in-canvas.page/scoped-transitions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/scoped-transitions/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>element.startViewTransition</category>
<category>view-transition-class</category>
<category>texElementSubImage2D</category>
<category>captureElementImage</category>
<description>startViewTransition() supplies the timing and a canvas draws the pictures: a WebGL shader on a canvas-scoped transition, nested scopes, one canvas for each list item, a group box as a drawing position, and one canvas for every change of an app.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/scoped-transitions/"><img src="https://html-in-canvas.page/scoped-transitions/social.jpg" width="1200" height="630" alt="The page &quot;View transitions drawn by a canvas&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas use a view transition for timing only and draw the old and new states of its HTML itself?</p>
<p><strong>Short answer:</strong> Yes. A transition scoped to the canvas gives one CSS-timed clock for each named element, in 2D and in WebGL. Nesting needs <code>view-transition-scope: all</code> on the canvas.</p>
<p>
Five experiments in which <code>startViewTransition()</code> supplies the timing and a canvas draws the pictures.
The content is HTML inside <code>&lt;canvas layoutsubtree&gt;</code>. Press the button under each one. The clocks show which pictures are live.
</p>
<h3>How it works</h3>
<p>
A view transition gives two things: timing (a set of CSS animations, one for each named element) and pictures (the old and new snapshots).
Inside a canvas the pictures aren't available, because the canvas renders none of its contents and no call hands a snapshot to script. The timing is available.
Experiments 1, 2 and 5 scope the transition to the canvas and read the group animations as clocks. Experiment 4 uses a document transition and reads the group's box. Experiment 3 leaves the moving to the browser and uses one canvas for each moving thing.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The canvas-scoped clock drives a WebGL shader.</strong> A WebGL canvas can be the scope of a transition like a 2D one. The shader gets one number for each tile, and CSS still sets the duration and easing. The page holds one WebGL context, through <code>lib/element-gl.js</code>.</li>
<li><strong>Nesting works when the canvas has <code>view-transition-scope: all</code> all the time.</strong> Without it, a transition on an ancestor that is already running has taken the names inside the canvas, and a transition started on the canvas then is rejected with "Snapshot capture failed". Started in the other order, or in the same task, both run without it.</li>
<li><strong><code>view-transition-class</code> matches canvases</strong> in a scoped transition, so one rule times a list of canvases. Each canvas stays live in its new snapshot and can distort its own content while the browser moves it.</li>
<li><strong>The group box of a canvas child can be drawn at, in a document transition.</strong> The canvas has to put the child's hit box back at its destination after each draw. If it does not, the group is retargeted to the place of the last draw every frame and stops moving.</li>
<li><strong>One canvas can draw every change of an app.</strong> The old state is an <code>ElementImage</code> taken in a <code>paint</code> handler. It stays drawable after the DOM has changed, and can be drawn in pieces with the nine-argument <code>drawElementImage()</code>.</li>
<li><strong>The old state is a picture.</strong> In experiment 5 only the new state is live and takes input during the change. <a href="https://html-in-canvas.page/transitions/"><code>&lt;live-transition&gt;</code></a> keeps both states live, at the cost of having both in the DOM.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/motion.md">findings/motion.md</a> in the repository.</p>
<h3>View transitions drawn by a canvas (<code>/scoped-transitions/</code>)</h3>
<p>Measured in headless Chromium 157 (C157) on 2026-11-21, by the page's live checks and by screenshots taken part way through each transition. Built from the five items that were listed as not tried under the View Transitions API section above.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>A WebGL canvas as the scope of <code>canvas.startViewTransition()</code>, with a vertex shader reading each tile's group as a clock</td><td>works</td><td>The canvas has <code>view-transition-name: none</code>. <code>texElementSubImage2D()</code> uploads the wrapper during the transition. Each tile is a 16 by 8 mesh that turns once, lifts and bends on <code>--vt-p</code>, and the fragment shader splits the colour channels along the direction of travel. CSS sets duration and easing.</td></tr>
<tr><td>Start a canvas-scoped transition while a transition on an ancestor is running</td><td>works with <code>view-transition-scope: all</code> on the canvas all the time</td><td>Without it the outer transition has taken the names inside the canvas, and the inner one is rejected with "Snapshot capture failed" and the console message "Element cannot participate in multiple transitions".</td></tr>
<tr><td>Canvas first, then its ancestor, or both in the same task</td><td>works without <code>view-transition-scope: all</code></td><td>The outer transition skips the names of a scope that is already active.</td></tr>
<tr><td><code>view-transition-class</code> on canvases, matched by <code>::view-transition-group(.class)</code> in a transition scoped to their list</td><td>works</td><td>One rule times five canvases. With the old snapshot hidden and the new one not animated, each canvas shows live and distorts its own row (24 horizontal strips drawn with the nine-argument <code>drawElementImage()</code>) while the browser moves it.</td></tr>
<tr><td>Draw a canvas child at the box of its <code>::view-transition-group()</code> in a document transition</td><td>works when the hit box is put back after each draw</td><td>The group has the right position and size at every frame. <code>updateElementGeometry()</code> returns the child's hit box to its destination after the draw.</td></tr>
<tr><td>The same without putting the hit box back</td><td>the group does not move</td><td>A 2D draw sets the child's position. The browser retargets the group to that position each frame, so the group stays where it started (20 px of 200 in the check).</td></tr>
<tr><td>One canvas draws every change of a small app from an <code>ElementImage</code> of the old state to the live new state</td><td>works</td><td><code>captureElementImage()</code> is called in a <code>paint</code> handler before <code>canvas.startViewTransition()</code>. The picture stays drawable after the DOM changes and can be drawn in columns or bands. Three effects: columns fall and turn, bands close, a circle opens from the tap.</td></tr>
<tr><td>All thirteen contexts lost at once (the browser's GPU process killed from outside, at rest and 250 ms into a nested transition)</td><td>recovers</td><td>Every 2D canvas fires <code>contextlost</code> and then <code>contextrestored</code> within 2.5 s, <code>/shared/context-guard.js</code> asks for a paint, and <code>lib/element-gl.js</code> restores the WebGL canvas. The transition that was running reports that it ran. No note and no plain HTML fallback appeared.</td></tr>
<tr><td>A 2D canvas whose context does not come back (faked: <code>isContextLost()</code> forced to true, then a <code>contextlost</code> event)</td><td>shown as plain HTML after 2.5 s</td><td><code>watch2d()</code> in <code>canvas-vt.js</code> calls the page, which takes the content out of the canvas and writes the context-guard summary in the status line. The buttons then make their changes without a transition.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li>A row drawn in strips with a different source and destination height per strip came out as dots. Source and destination strip heights must be equal.</li>
<li>A wave with a large phase range across the strips reads as a plain shear. A half sine across the row (ends fixed, middle bows) reads as a bend and keeps text legible.</li>
<li>The old boxes and the old picture must be taken before <code>startViewTransition()</code>, because no <code>paint</code> event arrives while the update callback is pending.</li>
<li>A clock inside a canvas repaints that canvas each time it ticks. The clocks now tick only when their canvas is in the viewport. With the jank guard's 4x CPU slowdown and software rendering the page reports 0.3 s of long tasks while loading (it was 7 to 12 s when every clock ticked).</li>
<li>The page uses one WebGL context, through <code>lib/element-gl.js</code>. It has no <code>readPixels</code> call and no second context for the checks.</li>
<li>2D backing stores stop at 2 device pixels per CSS pixel (<code>MAX_SCALE</code> in <code>canvas-vt.js</code>). At a ratio of 2.625 the eight visible 2D canvases held 1.7 times the pixels.</li>
<li>On an Android phone (Chrome 159, 2026-11-21, reported by the project owner) the 2D canvas of experiment 2 showed white with Chrome's broken-picture icon, which Chrome draws in a 2D canvas whose context is lost. Not reproduced here: killing the GPU process in headless Chromium 157 loses every context and all of them come back.</li></ul>
<h4>Not verified</h4>
<ul><li>The white flash in experiment 3. The project owner saw it on the phone (Chrome 159, Android, 2026-11-21) after pressing the sort buttons a few times; no report reached <code>/api/reports</code>. In headless Chromium 157 a run of 14 presses at 120 to 700 ms, with 95 screenshots of the list in the dark colour scheme, had no white pixel and no blank frame. Two changes were made without a reproduction: the canvases are reordered with <code>moveBefore()</code> and not <code>append()</code>, so they are never removed from the document, and a press during a running transition skips that transition, waits for it to finish and starts the next two frames later. Only the phone can say whether the flash is gone. If it is not, the next thing to try is drawing the rows in one canvas, so that the browser takes no snapshot of a canvas.</li>
<li>Whether the phone now keeps its canvases on <code>/scoped-transitions/</code>. The loss was traced on the project owner's phone (2026-11-21, see <code>findings/canvas-loss.md</code>) to a drawable 2D canvas made with <code>willReadFrequently: true</code>: once it is drawn into and read, every 2D context on the page is lost. The check rig on this page had one. It is now made without that option and its pixel is read from a <code>drawImage()</code> copy on a second, ordinary canvas. The same change was made to the check rigs of <code>/time-scrubber/</code> and <code>/particles/</code>. Headless Chromium 157 never showed the loss, so only the phone can confirm it.</li>
<li>Whether a 2D drawable canvas on Android fires <code>contextlost</code> and <code>contextrestored</code> at all. If it does not, neither the guard nor <code>watch2d()</code> can act.</li>
<li>Frame rate on a phone, and the WebGL experiment on a real GPU. Open <code>/scoped-transitions/</code> on the device and press Shuffle with "Run everything at 3 seconds" on.</li>
<li>WebGPU. Experiment 1 uses WebGL only. A WGSL version through <code>shared/backend.js</code> would verify it.</li>
<li>Touch selection and IME inside the app of experiment 5 during a transition.</li></ul>
<h4>For the index</h4>
<ul><li>View transitions: a transition scoped to a canvas works as a set of CSS-timed clocks for 2D and WebGL drawing (<code>/scoped-transitions/</code>, C157, measured).</li>
<li>View transitions: <code>view-transition-scope: all</code> on a canvas is needed to start a canvas-scoped transition inside a running ancestor transition (<code>/scoped-transitions/</code>, C157, measured).</li>
<li>View transitions: <code>view-transition-class</code> matches canvases in a scoped transition (<code>/scoped-transitions/</code>, C157, measured).</li>
<li>Hit testing: drawing a canvas child at its transition group box retargets the group unless <code>updateElementGeometry()</code> puts the hit box back (<code>/scoped-transitions/</code>, C157, measured).</li>
<li>Snapshots: an <code>ElementImage</code> taken before a DOM change is a usable old state for a transition drawn by the canvas (<code>/scoped-transitions/</code>, C157, measured).</li></ul>
<h4>Open ideas</h4>
<ul><li>A library element, for example <code>&lt;canvas-transition&gt;</code>, that wraps experiment 5: any DOM change inside it is drawn by a chosen effect.</li>
<li>The same clock driving a WebGPU shader, and effects that use both the old <code>ElementImage</code> and the live state as textures.</li>
<li>Navigation API <code>intercept()</code> calling the function of experiment 5 for route changes.</li></ul>
<p><a href="https://html-in-canvas.page/scoped-transitions/">Open View transitions drawn by a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Scroll-linked shaders</title>
<link>https://html-in-canvas.page/scroll-fx/</link>
<guid isPermaLink="true">https://html-in-canvas.page/scroll-fx/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>animation-timeline</category>
<category>scroll-state()</category>
<category>animation-trigger</category>
<category>@property</category>
<description>Blocks of a page burn in, unroll and melt as you scroll, and blur by the scroll speed. View timelines, a scroll-state() query and a timeline trigger set the shader inputs. The page has no scroll listener.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/scroll-fx/"><img src="https://html-in-canvas.page/scroll-fx/social.jpg" width="1200" height="630" alt="The page &quot;Scroll-linked shaders&quot;"></a></p>
<p><strong>Question:</strong> Can scroll-driven animations, <code>scroll-state()</code> queries and timeline triggers drive the shader that draws live DOM, with no scroll listener in the page?</p>
<p><strong>Short answer:</strong> Yes. All three set registered custom properties on elements inside a canvas, and scroll speed can be derived in CSS from two properties.</p>
<p>
Scroll the page. Each block below is HTML drawn through a fragment shader, and the shader's inputs are CSS custom properties that
scroll-driven animations, a <code>scroll-state()</code> container query and a scroll-triggered animation set. The page has no scroll
listener and no observer. Scroll fast to blur the blocks by the scroll speed. The buttons and fields keep working.
</p>
<h3>How it works</h3>
<ul>
<li>Each block with an <code>fx</code> attribute is moved into a canvas by <a href="https://html-in-canvas.page/shader-css/">the fx library</a>. The canvas takes the block's place in the page, so it scrolls with the page on the compositor like any other box.</li>
<li>The library reads four registered custom properties from the block once per frame while it is on screen and redraws when one changed. It doesn't know where the values come from. Here they come from <code>animation-timeline: view()</code>, <code>animation-timeline: scroll()</code>, a <code>scroll-state(stuck: top)</code> query and <code>animation-trigger</code>.</li>
<li>The percentage in each block's corner is the same property printed by a CSS counter inside the block. It changes the block's picture, so the block is uploaded to the texture again on those frames.</li>
<li>The shaders only move pixels. The blocks stay where layout put them for hit testing, so a button that is half burnt away is pressed at its normal position.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: a view timeline on an element that is a canvas child.</strong> The element has no box on the page outside its canvas, and its view timeline still follows the scroll position of the page.</li>
<li><strong>Works: scroll speed from two custom properties.</strong> A property with a transition that is set to <code>var()</code> of a scroll-animated property follows it late. The transition has to be on a descendant of the element that carries the animation.</li>
<li><strong>Works: <code>scroll-state(stuck)</code> across the canvas.</strong> The query container is the sticky holder outside the canvas. The bar it styles is inside the canvas.</li>
<li><strong>Works: <code>timeline-trigger</code> with <code>animation-trigger</code>.</strong> The animation runs by the clock and the shader follows it. Where the properties are missing the block falls back to the scrubbed timeline.</li>
<li><strong>Not available: the overscroll area.</strong> The plan for this page included a drawer on the overscroll area that stretches with the pull. No <code>overscroll-area</code> property exists in Chromium 157, so it wasn't built.</li>
<li><strong>Not verified here:</strong> whether the effects keep up with a touch scroll on a phone. The scroll moves on the compositor thread and the custom properties are read on the main thread, so the shader may be a frame or more behind the block's position. The WebGPU route on screen is also unverified in the test browser.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/effects-from-css.md">findings/effects-from-css.md</a> in the repository.</p>
<h3><code>/scroll-fx/</code> and <code>/shape-ui/</code></h3>
<p>Built from the Chrome APIs plan (<code>/chrome-apis/</code>, demos 6 and 7). Both pages use the <code>fx</code> attribute, with effects defined in the page. Chromium 157, software rendering.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>animation-timeline: view()</code> on an element that is a canvas child, animating <code>--fx-progress</code></td><td>works</td><td>The element's view timeline follows the page's scroll position although the element is only drawn through its canvas. The fx library reads the property once per frame.</td></tr>
<tr><td><code>animation-timeline: scroll(root)</code> on an ancestor, inherited by canvas children</td><td>works</td><td>Registered custom properties with <code>inherits: true</code> cross the shadow root and the canvas.</td></tr>
<tr><td>Scroll speed with no script: <code>--lag: var(--pos); transition: --lag 120ms linear</code>, speed = <code>--pos - --lag</code></td><td>works</td><td>The transition has to be on a descendant of the element whose animation moves <code>--pos</code>. Peak difference 0.42 of the scroll range in the check.</td></tr>
<tr><td><code>scroll-state(stuck: top)</code> container outside the canvas styling an element inside it</td><td>works</td><td>The sticky holder is the query container. The drawn bar gets <code>--fx-amount: 1</code> and a new background.</td></tr>
<tr><td><code>timeline-trigger</code> with <code>animation-trigger: play-forwards reset</code> on a canvas child</td><td>works</td><td>The animation runs by the clock after the scroll stops. In the small check fixture the reset on leaving was not seen within 200 ms. On the page it resets.</td></tr>
<tr><td>A drawer on the overscroll area</td><td>not built</td><td>No <code>overscroll-area</code> property in Chromium 157.</td></tr>
<tr><td><code>corner-shape</code>, <code>border-shape: circle()</code>, <code>clip-path: shape()</code> in the element's alpha</td><td>works</td><td>Corner pixel alpha 0, middle 255, for all three.</td></tr>
<tr><td>A normal from alpha: 16 samples in a 7 px disc, height = share inside, slope = alpha-weighted mean offset</td><td>works</td><td>One pass, no blur pass. Smooth between about 3 px and 14 px of bevel.</td></tr>
<tr><td>A shadow with the element's outline, drawn by the element's own shader</td><td>works</td><td>Alpha read 18 px towards the light, 8 jittered samples, inside 30 px of canvas bleed. It cannot darken a neighbouring canvas.</td></tr>
<tr><td><code>elementFromPoint()</code> in a corner cut away by <code>corner-shape</code>, <code>border-shape</code> or <code>clip-path</code></td><td>outline</td><td>Not the element, in a canvas and as plain DOM. Hit testing follows all three outlines.</td></tr>
<tr><td>Pressing: <code>:active</code> scales a key inside a shared picture</td><td>works</td><td>The alpha changes, so bevel and shadow follow with no code.</td></tr>
<tr><td>GLSL and WGSL versions of the eight new effects give the same picture</td><td>works</td><td>Mean difference under 0.4 of 255 per channel, WebGPU drawn into a texture on a software adapter.</td></tr></tbody></table>
<p>Both pages ask <code>/shared/backend.js</code> for WebGPU first and otherwise mark every element <code>fx-backend="shared"</code>, so a page opens one WebGPU device or one WebGL context (<code>/shared/fx-route.js</code>).</p>
<p><a href="https://html-in-canvas.page/scroll-fx/">Open Scroll-linked shaders</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Five more select pickers</title>
<link>https://html-in-canvas.page/select-ideas/</link>
<guid isPermaLink="true">https://html-in-canvas.page/select-ideas/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>appearance: base-select</category>
<category>drawElementImage</category>
<category>getImageData</category>
<category>popover</category>
<description>A customisable &lt;select&gt; drawn five more ways by a canvas inside its picker: 150 options under a magnifier, options on springs, a seat plan, a colour field that adds the colour you press as a new option, and a chosen option that flies into the button.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/select-ideas/"><img src="https://html-in-canvas.page/select-ideas/social.jpg" width="1200" height="630" alt="The page &quot;Five more select pickers&quot;"></a></p>
<p><strong>Question:</strong> How far can a canvas inside a customisable select go: can it draw an option twice, move options with physics, read its own pixels back to make a new option, and keep an option on screen after the picker has closed?</p>
<p><strong>Short answer:</strong> All four work in a 2D canvas. An option drawn twice is hit tested where it was drawn last. The pixels of the chosen option outlive the picker only as a copy of the canvas, because options stop painting when the select closes.</p>
<p>
Each control below is one <code>&lt;select&gt;</code> with <code>appearance: base-select</code>. Its options have been moved into a canvas
inside its picker, as on <a href="https://html-in-canvas.page/select/">/select/</a>, and the canvas does something a list of boxes cannot: it draws the same option
twice, moves options with springs, places them on a plan, reads its own pixels, and keeps the chosen option on screen after the
picker has gone. Open each one with a tap, a click or the keyboard. The values are read from the form in the usual way.
</p>
<h3>How it works</h3>
<p>
All five use <a href="https://html-in-canvas.page/select/">the select picker library</a>: the options are children of a <code>&lt;canvas content="drawable"&gt;</code>
inside the select, and a layout function says where each one is drawn on every frame. The select still owns the value, focus,
arrow keys, typeahead and the form entry. The listings below are the layouts.
</p>
<h3>Findings</h3>
<ul>
<li><strong>An option can be drawn more than once in a frame.</strong> The lens draws up to 30 options a second time. Both pictures appear. The hit box is where the option was drawn last, so a tap inside the lens reaches the enlarged option and the small copy underneath it takes no clicks.</li>
<li><strong>Hit testing keeps up with a simulation.</strong> The spring layout gives every option a new skewed, squashed transform on every frame, and <code>elementFromPoint()</code> returns the option at its drawn position while it moves.</li>
<li><strong>Only affine and perspective transforms have a hit box.</strong> An option that bends like cloth would need a mesh. <code>drawElementImage()</code> and <code>updateElementGeometry()</code> take one matrix for the whole element, so the spring layout skews and squashes each option as a whole. The mesh route on <a href="https://html-in-canvas.page/physical/">/physical/</a> maps the pointer by hand.</li>
<li><strong>A select doesn't check <code>disabled</code> when script chooses.</strong> A taken seat is a disabled option. The select itself ignores a click on it, but setting <code>option.selected</code> from script chooses it, so the picker library checks <code>disabled</code> before a slide-and-lift choice.</li>
<li><strong>The picker canvas can be read back.</strong> <code>drawImage()</code> from a 2D canvas that has had options drawn into it with <code>drawElementImage()</code> into another canvas works, and <code>getImageData()</code> on that copy gives the pixel. The colour field copies the pressed pixel into a 1 by 1 canvas and reads it there. It never calls <code>getImageData()</code> on the drawable canvas, because on an Android phone a drawable 2D canvas made with <code>willReadFrequently: true</code> and then read lost every 2D context on the page. It keeps a second canvas with only the gradient in it and reads that one if the copy is refused.</li>
<li><strong>An option added while the picker is open is drawn in the next frame.</strong> The new <code>&lt;option&gt;</code> is appended to the canvas and given the <code>drawable</code> attribute. It becomes the value and appears in <code>&lt;selectedcontent&gt;</code> like any other.</li>
<li><strong>The chosen option can't be drawn after the picker closes.</strong> The options stop painting in the frame the select closes. The pixels already in the picker canvas remain, so the flight copies the option's rectangle from that canvas with <code>drawImage()</code> into a small canvas shown as a popover. The picture is a still: a hover state or an animation in the option is frozen as it was on the last frame.</li>
<li><strong>Not verified on real hardware.</strong> Measured in Chromium 157 without a window, driven by Playwright with a mouse and emulated touch at 412 px. Sliding a finger in these pickers on Android Chrome, and the frame rate of the spring layout on a phone, haven't been tried on a device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/select-ideas.md">findings/select-ideas.md</a> in the repository.</p>
<p>Measured in C157 (headless Chromium 157, software rendering) on 2026-11-21, with Playwright: mouse, keyboard and emulated touch at 412 px. The page builds on <code>lib/select-picker.js</code> and the results in <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/select.md">select.md</a>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Draw the same <code>&lt;option&gt;</code> twice in one <code>paint</code> (small in a list, then enlarged inside a clipped circle)</td><td>works</td><td>Both pictures appear. The hit box is where the option was drawn last: <code>elementFromPoint()</code> in the lens returns the enlarged option (30 px tall, its small copy is 11 px).</td></tr>
<tr><td>156 options visible at once in one picker, no scrolling</td><td>works</td><td>Three columns at 0.3 scale, about 30 options redrawn in the lens each frame.</td></tr>
<tr><td>A new affine transform (translate, skew, squash) for every option on every frame</td><td>works</td><td><code>elementFromPoint()</code> returned a falling option at its drawn place while it moved 108 px in 3 frames.</td></tr>
<tr><td>An option that bends like cloth</td><td>not possible with one element</td><td><code>drawElementImage()</code> and <code>updateElementGeometry()</code> take one matrix per element. A mesh needs the pointer mapped by hand, as on <code>/physical/</code>.</td></tr>
<tr><td>70 options placed on arcs and rotated to face a point</td><td>works</td><td>Rotated options are hit where drawn. Arrow keys follow DOM order, which is row by row.</td></tr>
<tr><td>Disabled option chosen from script (<code>option.selected = true</code>)</td><td>the select accepts it</td><td>The select only refuses a real click. <code>SelectPicker.choose()</code> now returns early for a disabled option, which matters for layouts that choose on finger lift.</td></tr>
<tr><td><code>drawImage()</code> from a 2D canvas after <code>drawElementImage()</code> of options into a second canvas, then <code>getImageData()</code> on the copy</td><td>works</td><td>The canvas is not tainted. Direct <code>getImageData()</code> on the drawable canvas also worked in headless C157, but the page no longer does it: on Paul's Android phone (Chrome 159, reported 2026-11-21) a drawable 2D canvas that is read with <code>getImageData()</code> after being created with <code>willReadFrequently: true</code> loses every 2D context on the page. The field canvas (not drawable) no longer asks for <code>willReadFrequently</code>.</td></tr>
<tr><td><code>drawImage(pickerCanvas, …)</code> into another canvas</td><td>works</td><td>Used to copy the chosen option's rectangle.</td></tr>
<tr><td>Append an <code>&lt;option drawable&gt;</code> to the picker canvas while the picker is open</td><td>works</td><td>It is drawn and hit tested on the next frame, becomes the value, and appears in <code>&lt;selectedcontent&gt;</code>.</td></tr>
<tr><td><code>drawElementImage(option)</code> in the frame after the picker closes</td><td>fails</td><td>"No cached paint record for element."</td></tr>
<tr><td>Keep the chosen option on screen after the close</td><td>works as a still</td><td>The option's rectangle is copied from the picker canvas into a <code>&lt;canvas popover="manual"&gt;</code>, which is animated to the button with the Web Animations API.</td></tr>
<tr><td><code>label</code> attribute on an option in a customisable select</td><td>replaces the option's content</td><td>The picker then draws the label text, not the option's child elements. The page keeps names in <code>data-name</code>.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Moving the options of a select into a canvas one at a time changes the value. Each move makes the select pick an option again, and it ends on the last one. <code>ideaPicker()</code> puts <code>selectedIndex</code> back. <code>/select/</code> did not show this because its options are added after the canvas exists.</li>
<li>An option wider than the lens showed only its right-hand part in the lens. The lens is now centred on a column across, and follows the pointer only down the list.</li>
<li>One tap opens one picker, so the live checks put five canvases, one per layout, in a scrolling box inside one test select, and scroll that box between checks.</li>
<li>A layout cannot ask <code>SelectPicker</code> for another frame. The spring layout calls <code>canvas.requestPaint()</code> itself from <code>requestAnimationFrame</code> while anything is still moving.</li></ul>
<h3>Not verified</h3>
<ul><li>Android Chrome on a phone: sliding a finger in each picker, and the frame rate of the spring layout. Open <code>/select-ideas/</code> on the phone and use each select.</li>
<li>Whether the copied picture of the chosen option is sharp at the phone's device pixel ratio. The copy is made at the canvas's backing-store size.</li>
<li>A screen reader on the seat plan. Each seat keeps its text ("Row C, seat 7" is in a hidden span), which was not listened to.</li></ul>
<h3>Open ideas</h3>
<ul><li>A lens drawn by a shader, which bends the text continuously where this one draws each option flat.</li>
<li>Throwing an option at a target to choose it, with the spring layout's physics.</li>
<li>A seat plan over a photograph of the room.</li></ul>
<p><a href="https://html-in-canvas.page/select-ideas/">Open Five more select pickers</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Six more select and selection experiments</title>
<link>https://html-in-canvas.page/select-selection/</link>
<guid isPermaLink="true">https://html-in-canvas.page/select-selection/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>select multiple</category>
<category>appearance: base-select</category>
<category>Selection</category>
<category>drawElementImage</category>
<category>updateElementGeometry</category>
<description>A select multiple whose options are chips chosen with a lasso, an input that opens a customisable select with no button, text selected on a plane in perspective, a translation written over the selected sentences, a pulse for each word selected, and selected letters in an input that move in a wave.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/select-selection/"><img src="https://html-in-canvas.page/select-selection/social.jpg" width="1200" height="630" alt="The page &quot;Six more select and selection experiments&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw the options of a <code>&lt;select multiple&gt;</code>, can a customisable select with no button serve an <code>&lt;input&gt;</code> as its suggestion list, and does the browser's own text selection still work on text that is drawn in perspective, written over by a translation, or inside an <code>&lt;input&gt;</code>?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157, with limits. A canvas inside a list box select isn't laid out, so the select goes inside the canvas. <code>showPicker()</code> takes the focus from the input, so it's put back. A selection inside an input has no rectangles, so they're measured.</p>
<p>
Six questions left on the lists at the end of <a href="https://html-in-canvas.page/select/">/select/</a>, <a href="https://html-in-canvas.page/datalist/">/datalist/</a>,
<a href="https://html-in-canvas.page/inputs/">/inputs/</a> and <a href="https://html-in-canvas.page/selection/">/selection/</a>. Each one keeps the browser's own element, a
<code>&lt;select&gt;</code>, an <code>&lt;input&gt;</code> or selectable text, and has a 2D canvas draw it. Each section says what was
asked of the API and what happened.
</p>
<h3>How it works</h3>
<p>
Every canvas on this page has a 2D context. None reads pixels back. An element that is drawn in pieces is drawn with the
nine-argument form of <code>drawElementImage()</code>, which takes a source rectangle. Each draw moves the element's one hit box, so
each experiment ends its frame by putting the hit box where it wants it: with a last draw at no opacity, or with
<code>updateElementGeometry()</code> and a matrix. A demo starts when its section comes within 300 px of the screen.
</p>
<h3>Findings</h3>
<ul>
<li><strong>A canvas inside a <code>&lt;select multiple&gt;</code> isn't laid out.</strong> The parser keeps it, but its box is 0 by 0 and <code>drawElementImage()</code> of an option throws "No cached paint record", with and without <code>appearance: base-select</code>. Putting the select inside the canvas works: an option with the <code>drawable</code> attribute can be drawn on its own, anywhere.</li>
<li><strong>A click on an option drawn outside the select's own box chooses nothing.</strong> Measured with real clicks and emulated taps from a test script, not by a live check: <code>elementFromPoint()</code> gave the option in some runs and the canvas in others, so it isn't evidence either way. With the select's box covering the canvas, click, Ctrl click, Shift click, dragging, the arrow keys and a touch tap all choose the option that is drawn under the pointer.</li>
<li><strong>A list box option draws its text and its <code>::before</code>, and no child elements.</strong> The swatch on each chip is a <code>::before</code>. The colour of a chosen option is the browser's.</li>
<li><strong><code>showPicker()</code> on a select needs a user activation, and a key press is one.</strong> It moves the focus to an option, and the next key goes to the select. Calling <code>focus()</code> on the input straight after leaves the picker open, and typing carries on.</li>
<li><strong>A source rectangle stays on the hit box.</strong> After a nine-argument draw, only the source rectangle of that draw is hit tested, and <code>updateElementGeometry()</code> moves that cut box without making it whole. A five-argument draw at no opacity makes it whole again.</li>
<li><strong>A 2D canvas can set a hit box in perspective.</strong> <code>updateElementGeometry()</code> takes a 4 by 4 matrix with a perspective row on a canvas with a 2D context. Selecting with the pointer then lands on the letter that is drawn there, although the picture was made from 2 px strips.</li>
<li><strong>Range rectangles under that matrix are bounding boxes.</strong> The page measures the selected lines on a second copy of the article that is laid out in the canvas and never drawn. The copy needs the <code>drawable</code> attribute too: <code>updateElementGeometry()</code>, which moves its hit box out of the way, throws for a child without it.</li>
<li><strong>Text written by the canvas over a sentence doesn't change the selection.</strong> The Range, the highlight geometry and the copied text stay those of the original words.</li>
<li><strong><code>Translator.availability()</code> didn't settle in headless Chromium 157.</strong> The promise neither resolved nor rejected, so the page gives it 1.5 s and then uses the table. The API route isn't verified.</li>
<li><strong>A selection inside an <code>&lt;input&gt;</code> or <code>&lt;textarea&gt;</code> has no Range.</strong> <code>measureText()</code> with the input's font gives the letters of an input. A hidden block with the same font and width gives those of a textarea.</li>
<li><strong>Not verified on real hardware.</strong> These results are from Chromium 157 driven by Playwright. On Android a <code>&lt;select multiple&gt;</code> is a button that opens a dialog, so its options may have no picture: the page then draws the labels as text and says so. Vibration, touch selection handles on the leaning text, and the on-screen keyboard with the suggestion list have not been tried.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/select-selection.md">findings/select-selection.md</a> in the repository.</p>
<p>Measured on 2026-11-21 in headless Chromium 157 (C157), driven by Playwright with a mouse, a keyboard and emulated touch at 412 px wide. Nothing here has been run on a phone. Backlog group 24 of <code>PLAN.md</code>: items 24.1 to 24.6.</p>
<p>Every canvas on the page has a 2D context. The page makes no WebGL or WebGPU context and reads no pixels back. <code>npm run check:jank -- /select-selection/</code> reports <code>gl 0/0</code>, <code>reads 0</code>, 2.6 MB of canvases.</p>
<h3>A select multiple drawn by a canvas (24.1)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>A <code>&lt;canvas layoutsubtree&gt;</code> inside <code>&lt;select multiple&gt;</code>, with the options in it (the arrangement <code>/select/</code> uses for a customisable select)</td><td>fails (live check, expected failure)</td><td>The parser keeps the canvas. Its box is 0 by 0 px, a <code>paint</code> event fires, and <code>drawElementImage(option)</code> throws "No cached paint record for element". Same with <code>appearance: base-select</code> on the select.</td></tr>
<tr><td>The select as a <code>drawable</code> child of the canvas, each option also <code>drawable</code></td><td>works</td><td><code>drawElementImage(option, …)</code> draws one option anywhere. The option is left out of the select's own picture.</td></tr>
<tr><td>Hit testing of an option drawn that way</td><td>works when the select's box covers the place</td><td>With the select's box as large as the canvas: click, Ctrl click, Shift click, a mouse drag across options, the arrow keys with Shift, Ctrl and A, and an emulated touch tap all choose the option drawn under the pointer. A tap toggles one option.</td></tr>
<tr><td>An option drawn outside the select's own layout box</td><td>a real click or tap chooses nothing</td><td>Measured with Playwright clicks and taps (select 160 px wide, options drawn 130 and 250 px in). <code>elementFromPoint()</code> returned the option in some runs and the canvas in others for the same arrangement, so it is not used as evidence and there is no live check for this row.</td></tr>
<tr><td>What a list box option draws</td><td>its text and its <code>::before</code></td><td>Child elements of the option (<code>&lt;i&gt;</code>, <code>&lt;b&gt;</code>) are not drawn. Border, radius, padding and width on the option apply. The background of a chosen option is the browser's, and in touch emulation with a dark scheme it was not visible, so the canvas marks chosen chips itself.</td></tr>
<tr><td>A lasso: pointer capture on the canvas after 8 px of movement, then <code>option.selected</code> set from script</td><td>works</td><td>The list box stops its own drag selection once the canvas has the pointer. The library fires <code>input</code> and <code>change</code>.</td></tr>
<tr><td>A touch drag on the canvas with the lasso off</td><td>scrolls the page</td><td><code>touch-action: pan-y</code>. With the lasso on it is <code>none</code>.</td></tr></tbody></table>
<h3>Rich suggestions from a select with no button (24.2)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td><code>select.showPicker()</code> on a customisable select whose <code>&lt;button&gt;</code> is <code>display: none</code></td><td>opens the picker</td><td>From an <code>input</code> event handler. From a timer 6 s after the last key it throws <code>NotAllowedError</code>: it needs a user activation.</td></tr>
<tr><td>Focus after <code>showPicker()</code></td><td>moves to an option</td><td>The next key press goes to the select. <code>input.focus()</code> straight after leaves the picker open and typing carries on in the input.</td></tr>
<tr><td>The select laid over the input (<code>position: absolute; inset: 0; pointer-events: none</code>)</td><td>the picker is placed beside the input's box, above or below</td><td>With a select of no height under the input the picker opened over the input when there was no room below. <code>::picker(select)</code> needs <code>pointer-events: auto</code> again.</td></tr>
<tr><td>Options with markup (<code>&lt;b&gt;</code>, <code>&lt;small&gt;</code>, a <code>::before</code> swatch) drawn by the picker's canvas</td><td>drawn and hit on their rows</td><td>A <code>&lt;datalist&gt;</code> option draws only its label (<code>findings/datalist.md</code>).</td></tr>
<tr><td>A select with <code>selectedIndex = -1</code></td><td>submits no entry</td><td>So the form has no station code until a row is taken.</td></tr>
<tr><td>Focus when a row is tapped</td><td>goes to the select as the picker closes</td><td>A <code>focus()</code> on the input in a microtask is too early. A 0 ms timer works.</td></tr></tbody></table>
<h3>Selection in 3D (24.3)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>A perspective picture on a 2D canvas</td><td>works, in strips</td><td>2 px strips with the nine-argument <code>drawElementImage()</code>, each at the width and place its row has on the plane: 118 calls for the article, plus the selected lines again. Exact for a turn about a horizontal axis, because rows stay horizontal.</td></tr>
<tr><td><code>updateElementGeometry()</code> with a 4 by 4 matrix that has a perspective row, on a canvas with a 2D context</td><td>works</td><td><code>caretPositionFromPoint()</code> at the drawn place of three words lands inside each word at 48 degrees (live check). A mouse drag selects the text under the pointer.</td></tr>
<tr><td>The hit box after a nine-argument draw</td><td>cut to that draw's source rectangle (live check, expected failure)</td><td><code>updateElementGeometry()</code> then moves the cut box and does not make it whole. With only strips drawn, the article was hit in its last 2 px and nowhere else. A five-argument draw at <code>globalAlpha</code> 0 before <code>updateElementGeometry()</code> restores it.</td></tr>
<tr><td><code>Range.getClientRects()</code> under the perspective matrix</td><td>bounding boxes of slanted quads</td><td>A sentence measured 254 by 12 px on the plane and 265 by 20 px in a copy with no transform. The page measures on a second copy of the article that is laid out in the canvas and never drawn.</td></tr>
<tr><td><code>updateElementGeometry()</code> on a canvas child with no <code>drawable</code> attribute</td><td>throws</td><td>"Descendants passed to updateElementGeometry must have the 'drawable' attribute". The copy keeps the attribute so that its hit box can be moved away.</td></tr></tbody></table>
<h3>Translate the selection in place (24.4)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Text written with <code>fillText()</code> over the line rectangles of a sentence</td><td>works</td><td>The rectangles come from a Range on the sentence. A longer translation is narrowed by the same factor on every line (French 85%, German 65 to 77% for these sentences).</td></tr>
<tr><td>The DOM, the selection and a copy after that</td><td>unchanged</td><td>The article still holds the English. A selection across a covered sentence copies the English.</td></tr>
<tr><td>The browser's selection highlight</td><td>taller than the range rectangles</td><td>It is as tall as the line box, so the cover uses the computed <code>line-height</code>.</td></tr>
<tr><td><code>Translator.availability()</code></td><td>did not settle</td><td>The promise neither resolved nor rejected in headless C157. The page waits 1.5 s and uses a table of the five sentences written in advance.</td></tr></tbody></table>
<h3>Haptics on selection change (24.5)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>A pulse per word and per sentence, from counts taken on <code>selectionchange</code></td><td>works</td><td>Five steps gave word, word, word, sentence, word (live check).</td></tr>
<tr><td><code>navigator.vibrate()</code> during a mouse drag</td><td>returned true 13 times of 13</td><td>In headless C157, which has no motor. This says the call was accepted, not that anything moved.</td></tr></tbody></table>
<h3>Selection effects for form controls (24.6)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Reason or detail</th></tr></thead><tbody><tr><td>Rectangles of a selection inside <code>&lt;input&gt;</code></td><td>from <code>measureText()</code></td><td>With the input's computed font, padding, border and <code>scrollLeft</code>. "Narrowboat" measured 94.8 px both ways (live check).</td></tr>
<tr><td>Rectangles of a selection inside <code>&lt;textarea&gt;</code></td><td>from a hidden block</td><td>Same font, padding, border and wrapping width, laid out as a canvas child that is never drawn. A Range there gives one rectangle per letter, on the right lines.</td></tr>
<tr><td>Letters drawn again from the control's picture, one source rectangle each, with <code>globalCompositeOperation</code> <code>multiply</code> (or <code>screen</code> on a dark control)</td><td>works</td><td>The slice carries the control's background, and the blend leaves the letter on the band. <code>::selection { background: transparent }</code> keeps the browser's highlight out of the slices.</td></tr>
<tr><td>The control's hit box after the slices</td><td>restored by a draw at no opacity</td><td>Checked at both ends of the input.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>elementFromPoint()</code> on an option drawn outside its list box's box is not stable between runs and environments. Real clicks were the evidence.</li>
<li>A check that calls <code>showPicker()</code> must run first, while the tap that started the checks still counts.</li>
<li><code>checkBench()</code> shows its panel when it is called. Call it from the first check that needs it, not when the module loads.</li>
<li>Selecting on the leaning plane selected the whole article until the hit box was made whole again (the source rectangle row above), and the never-drawn copy was moved out of the way.</li></ul>
<h3>Not verified</h3>
<ul><li>Android: a <code>&lt;select multiple&gt;</code> there is a button that opens a dialog. Whether its options have a picture in a canvas is not known. If they have none, the page draws the labels as text and handles taps itself (forced and tested in a live check); the page's note says which route ran.</li>
<li>Touch selection handles and the copy menu on the leaning text, and long-press selection in the two controls.</li>
<li>Vibration on a device with a motor. The page prints what <code>vibrate()</code> returned.</li>
<li>The on-screen keyboard together with the suggestion picker, and whether the picker stays open while typing on Android.</li>
<li>The Translator API route: <code>availability()</code> never answered in the test browser.</li>
<li>Frame time of about 140 strip draws per paint on a phone. They run only when the angle or the selection changes.</li>
<li>A screen reader on the suggestion input (<code>role="combobox"</code> is set, <code>aria-activedescendant</code> needs option ids).</li></ul>
<h3>Open ideas</h3>
<ul><li>A turn about both axes, which needs a different strip direction or a GPU route.</li>
<li>The lasso on a customisable select with <code>multiple</code>, when Chromium supports <code>appearance: base-select</code> for it with a canvas child.</li>
<li>Per-letter effects in a textarea with more than 240 selected letters.</li></ul>
<p><a href="https://html-in-canvas.page/select-selection/">Open Six more select and selection experiments</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Customisable select</title>
<link>https://html-in-canvas.page/select/</link>
<guid isPermaLink="true">https://html-in-canvas.page/select/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>appearance: base-select</category>
<category>drawElementImage</category>
<category>WebGL</category>
<category>WebGPU</category>
<description>A &lt;select&gt; with appearance: base-select whose options are drawn by a canvas inside the picker: a wheel, a fisheye list, a radial menu, a 3D carousel, a hand of cards, a colour grid and a helix. Also a canvas in the button, a canvas inside each option, and a select drawn in a canvas.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/select/"><img src="https://html-in-canvas.page/select/social.jpg" width="1200" height="630" alt="The page &quot;Customisable select&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas inside a customisable <code>&lt;select&gt;</code> draw the options while the select keeps the value, the keyboard and hit testing? And does the picker of a select inside a canvas draw into that canvas?</p>
<p><strong>Short answer:</strong> Options inside a canvas inside the select work, in 2D, WebGL and WebGPU. The picker of a select that is in a canvas stays in the top layer and isn't drawn by that canvas.</p>
<p>
A select with <code>appearance: base-select</code> has a picker made of ordinary HTML. I tested the two ways to combine that
with HTML-in-canvas: a canvas inside the select that draws the options, and a select inside a canvas. Each select below is one
<code>&lt;select&gt;</code> element with real <code>&lt;option&gt;</code> children. Open them with a tap, a click or the keyboard.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Options can live in a canvas inside the select.</strong> With <code>appearance: base-select</code>, <code>&lt;select&gt;&lt;canvas content="drawable"&gt;&lt;option drawable&gt;</code> parses, <code>select.options</code> finds the options, and the canvas draws each one wherever it likes. Click, hover, <code>:checked</code>, arrow keys, typeahead, Enter and Escape are still the select's own. The four pickers above add no keyboard code.</li>
<li><strong>Hit testing follows the drawing.</strong> In a 2D canvas, <code>drawElementImage()</code> under a transform moves the option's hit box with it. With WebGL or WebGPU, <code>updateElementGeometry()</code> accepts the carousel's perspective matrix. Where two options overlap, the one drawn last gets the click. <code>z-index</code> on the options doesn't change that.</li>
<li><strong>An option that isn't drawn keeps its last hit box.</strong> The library moves options that are off the wheel or carousel far outside the canvas. They stay reachable with the arrow keys, and the layout turns to the focused option.</li>
<li><strong>The select fires no event when its picker opens.</strong> No <code>toggle</code> or <code>beforetoggle</code> reached the select in Chromium 157. The canvas's first <code>paint</code> event is the earliest signal. Before that the options have no paint record and drawing them throws.</li>
<li><strong>There's no <code>hidePicker()</code>.</strong> <code>blur()</code>, a synthetic Escape key, <code>option.click()</code> and toggling <code>disabled</code> or <code>inert</code> all leave the picker open. Showing an empty <code>popover="auto"</code> element closes it, because the picker is in the same stack. The fisheye and radial pickers use that after a slide-and-lift gesture, because a touch that moved sends no click. Setting <code>appearance: auto</code> for one style recalculation also closes the picker, but if the mouse is over the picker at that moment the select's computed <code>appearance</code> stays <code>auto</code> afterwards and it becomes the browser's own select.</li>
<li><strong>A press chooses on mouseup, not on click.</strong> A mouse drag that ends over an option chooses it. The library captures the pointer on the canvas once a drag passes 7 px, so the release goes to the canvas.</li>
<li><strong><code>touch-action: none</code> didn't stop the page panning.</strong> With touch emulation, a vertical drag on the wheel scrolled the page and cancelled the pointer, with <code>touch-action: none</code> on the canvas and on the options. The library cancels <code>touchmove</code> inside the picker instead.</li>
<li><strong>One tap opens one picker.</strong> <code>showPicker()</code> needs user activation and uses it up, and synthetic clicks and keys don't open a picker. The live checks below therefore share a single test select.</li>
<li><strong>A canvas in the button can draw <code>&lt;selectedcontent&gt;</code>.</strong> With <code>&lt;button&gt;&lt;canvas&gt;&lt;selectedcontent drawable&gt;</code> the browser still fills in the chosen option on every change, and the canvas draws it. The hand of cards and the helix above keep the pixels of the old value and roll the new one in.</li>
<li><strong>A canvas inside an option works, with two limits.</strong> It can draw its own drawable children once the picker is open (while closed there is no paint record). <code>&lt;selectedcontent&gt;</code> clones the canvas element on every change, and the clone has no pixels and no <code>paint</code> handler.</li>
<li><strong>A select in a canvas keeps its picker out of the canvas.</strong> The picker is top-layer content. It isn't in the picture <code>drawElementImage(select)</code> draws, and the outer canvas can't draw an option of the open picker either ("No cached paint record"). It opens upright next to the bounding box of the drawn button, whatever transform the button was drawn with. To transform the picker too, put a canvas inside the select as above.</li>
<li><strong>The picker can't animate out.</strong> When the select closes, the options stop painting in the same frame, so the canvas has nothing to draw a closing animation with. The opening animation runs because the picker is already open.</li>
<li><strong>Not verified on real hardware.</strong> These results are from Chromium 157 with software rendering, driven by Playwright with mouse and emulated touch. The WebGPU route was checked by rendering to a texture and reading it back, not by showing it. Touch dragging inside the picker on Android Chrome is something I haven't tried on a device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/select.md">findings/select.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 with software rendering on 2026-11-21, driven by Playwright with a mouse, a keyboard and emulated touch. Not yet tried on a phone.</p>
<p>A select with <code>appearance: base-select</code> has a picker made of HTML in the top layer. Two combinations were tested: a canvas inside the select, and a select inside a canvas.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>&lt;select&gt;&lt;canvas content="drawable"&gt;&lt;option drawable&gt;</code></td><td>works</td><td>The select collects options from all its descendants. <code>select.options</code>, the value, the form entry, arrow keys, typeahead, Enter and Escape are unchanged.</td></tr>
<tr><td>The picker canvas draws each option under its own 2D transform</td><td>works</td><td><code>drawElementImage()</code> moves the option's hit box. Click, hover and <code>:checked</code> are the browser's.</td></tr>
<tr><td>Options as WebGL textures with a perspective matrix</td><td>works</td><td><code>texElementSubImage2D()</code>, then <code>updateElementGeometry()</code> with the same matrix the shader uses.</td></tr>
<tr><td>Options as WebGPU textures</td><td>works off screen</td><td><code>drawElementImageToTexture()</code> into a texture, read back. Not shown on a canvas here: the software adapter loses its device when it presents.</td></tr>
<tr><td>Two options overlap</td><td>the one drawn last gets the click</td><td>The last <code>drawElementImage()</code> or <code>updateElementGeometry()</code> wins. <code>z-index</code> on the options has no effect.</td></tr>
<tr><td>An option the canvas does not draw</td><td>keeps its last hit box</td><td>The library moves it far outside the canvas. It stays reachable by arrow key.</td></tr>
<tr><td><code>toggle</code> or <code>beforetoggle</code> on the select when the picker opens</td><td>no event</td><td>The canvas's first <code>paint</code> event is the earliest signal. Before it the options have no paint record.</td></tr>
<tr><td>Close the picker from script</td><td>works, with a workaround</td><td>There is <code>showPicker()</code> and no <code>hidePicker()</code>. <code>blur()</code>, a synthetic Escape, <code>option.click()</code>, <code>disabled</code>, <code>inert</code> and <code>display: none</code> restored in the same task all leave it open. Showing an empty <code>popover="auto"</code> element closes it: the picker is in the popover stack.</td></tr>
<tr><td>Close the picker by setting <code>appearance: auto</code> for one style recalculation</td><td>closes it, then breaks the select</td><td>Chromium logs a console warning. If the mouse is over the picker at that moment, the select's computed <code>appearance</code> stays <code>auto</code> afterwards, whatever the stylesheet and inline style say, and it is the browser's own select until reload.</td></tr>
<tr><td>Open several pickers from one tap</td><td>fails</td><td><code>showPicker()</code> needs user activation and uses it up. One tap opens one picker. Synthetic clicks and key events do not open one.</td></tr>
<tr><td>Mouse press on an option, drag, release over another option</td><td>chooses the second</td><td>The select chooses on mouseup. The library captures the pointer on the canvas once a drag passes 7 px.</td></tr>
<tr><td><code>touch-action: none</code> on the picker canvas and on the options</td><td>does not stop the page panning</td><td>In touch emulation a vertical drag in the picker scrolled the page and cancelled the pointer. Cancelling <code>touchmove</code> stops it.</td></tr>
<tr><td>An animation when the picker closes</td><td>fails</td><td>The options stop painting in the frame the picker closes, so the canvas has nothing to draw.</td></tr>
<tr><td>A canvas inside an option draws its own drawable child</td><td>works while open</td><td>With the picker closed: "No cached paint record". A plain canvas in an option that is given pixels with <code>drawImage()</code> can be drawn at any time.</td></tr>
<tr><td><code>&lt;selectedcontent&gt;</code> with a canvas in the chosen option</td><td>clones the element only</td><td>The clone has no pixels and no <code>paint</code> handler, and it is replaced on every change. Its cloned children are drawable in it.</td></tr>
<tr><td><code>position-area: center</code> on <code>::picker(select)</code></td><td>works</td><td>The radial picker opens centred on the button.</td></tr>
<tr><td>A select as a drawable child of a canvas, drawn rotated</td><td>works</td><td>The button is hit tested where it is drawn.</td></tr>
<tr><td>The picker of that select in the canvas's picture</td><td>fails</td><td>The picker is top-layer content. The browser paints it upright, anchored to the bounding box of the drawn button.</td></tr>
<tr><td>The outer canvas draws an option of the open picker</td><td>fails</td><td>"No cached paint record for element."</td></tr>
<tr><td>A canvas-drawn picker inside a select that is itself drawn by a canvas</td><td>works</td><td>Two nested drawable canvases. The inner one is in the top layer while the picker is open.</td></tr>
<tr><td>A canvas in the select's <code>&lt;button&gt;</code> with <code>&lt;selectedcontent drawable&gt;</code> inside it</td><td>works</td><td>The browser still fills <code>&lt;selectedcontent&gt;</code> on every change, and the canvas draws it. <code>rollSelected()</code> keeps the old value's pixels and rolls the new value in.</td></tr>
<tr><td><code>display</code> set on <code>::picker(select)</code> without <code>:open</code></td><td>renders the closed picker</td><td>A rule such as <code>::picker(select) { display: flex }</code> overrides the rule that hides the closed picker. Write it as <code>select:open::picker(select)</code>.</td></tr></tbody></table>
<p>What would help:</p>
<ul><li><code>hidePicker()</code>, and <code>toggle</code> events on the select, as popovers have.</li>
<li>A way for a picker's content to keep painting for a moment after the select closes, so a canvas can draw a closing animation or move the chosen option into the button.</li>
<li><code>&lt;selectedcontent&gt;</code> cloning a canvas with its bitmap, or an event when it replaces its clone.</li>
<li><code>touch-action</code> taking effect for elements drawn by a canvas in the top layer. This needs checking on a real phone before it is reported.</li></ul>
<p><a href="https://html-in-canvas.page/select/">Open Customisable select</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Selected letters as particles</title>
<link>https://html-in-canvas.page/selection-glyphs/</link>
<guid isPermaLink="true">https://html-in-canvas.page/selection-glyphs/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Range.getClientRects()</category>
<category>drawElementImage</category>
<category>clip()</category>
<description>Select text in a canvas and its letters come loose, fall into a pile, swirl and return. Each letter is a Range rectangle, drawn from a snapshot or from the live element through a clip. The DOM text doesn't change.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/selection-glyphs/"><img src="https://html-in-canvas.page/selection-glyphs/social.jpg" width="1200" height="630" alt="The page &quot;Selected letters as particles&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas take single characters out of an element's picture and draw them somewhere else, while the text stays whole in the DOM?</p>
<p><strong>Short answer:</strong> Yes, with one Range per character and an even-odd clip.</p>
<p>
Select some of the text. When the selection stops changing, its letters come loose and fall to the bottom of the article. “Swirl” moves them in rings and “Put them back” returns each one to its place. The text in the DOM doesn't change at any point.
</p>
<h3>How it works</h3>
<p>
A <code>Range</code> around a single character has one client rectangle. The page collects those rectangles for the selection and gives each one a particle. On every frame the canvas draws the article through a clip path that leaves out the home rectangle of every loose letter, then draws each letter at its particle's position and angle.
A letter comes from one of two places. The snapshot is a copy of the canvas taken at the moment the letters are let go, and each letter is a <code>drawImage()</code> of a small part of it. The live route calls <code>drawElementImage()</code> once per letter with a clip the size of the letter, so a letter in the air still follows changes to the element (hover, a new colour, an edit).
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.</p>
<ul>
<li><strong>One character has one rectangle.</strong> A <code>Range</code> from offset <code>i</code> to <code>i + 1</code> gives the box of that character at its drawn position. The box is the advance width and the line's text height, not the ink, so a tall italic letter can lose a sliver to its neighbour's box.</li>
<li><strong>The canvas is transparent where the element has no ink.</strong> The article has no background of its own, so a piece of the canvas is a letter with nothing behind it. No colour keying is needed.</li>
<li><strong>An even-odd clip removes letters from the element's picture.</strong> The text is drawn once, with holes. The DOM text, the selection and copy are unchanged while the letters are away.</li>
<li><strong>Both ways of drawing a letter work.</strong> The timing check below gives the cost of each on the device that runs it. The live route replays the element's whole paint record once per letter.</li>
<li><strong>A resize moves every home rectangle</strong>, so the page puts the text back whole when the element's width changes.</li>
</ul>
<p><strong>Not verified:</strong> frame rate on a phone with several hundred letters, and the automatic drop after a touch selection made with the Android handles (the page waits 0.7 s after the last change).</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/selection.md">findings/selection.md</a> in the repository.</p>
<h3>Five pages drawn from ranges (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>, <code>/redact/</code>, <code>/selection-heat/</code>, <code>/share-card/</code>)</h3>
<p>Measured in headless Chromium 157 (Linux, software renderer, device scale factor 2) on 2026-11-21. Each row is a live check on the page named. The first four pages are 2D effects registered on <code>&lt;selection-fx&gt;</code> with <code>defineSelectionEffect()</code> from their own modules. Shared helpers are in <code>lib/selection-tools.js</code> and shared styles in <code>lib/selection-article.css</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Rectangles of a range that is not selected (<code>/selection-peers/</code>)</td><td>works</td><td><code>Range.getClientRects()</code> needs no selection. A canvas draws any number of other readers' ranges with no change to the DOM or to the document's selection (HTML and selection compared before and after).</td></tr>
<tr><td>A selection sent as two offsets into <code>textContent</code> and rebuilt in another document</td><td>works</td><td>Round trip checked across an inline element. A message on a <code>BroadcastChannel</code> arrived in 25 ms and the range was drawn 48.2 px wide for 4 characters of 12 px.</td></tr>
<tr><td>A same-origin frame as a second reader</td><td>works</td><td>Each document has its own selection, so selecting in the frame does not clear the page's selection. Checked with a script, not a live check: both selections were held at once and each side drew the other's range.</td></tr>
<tr><td>One <code>Range</code> per character (<code>/selection-glyphs/</code>)</td><td>works</td><td>12 rectangles for 12 letters, each 12.0 px wide in a 20 px monospace font. The box is the advance width and the line's text height, not the ink.</td></tr>
<tr><td>Letters taken out of the element's picture with an even-odd clip and drawn elsewhere</td><td>works</td><td>After dropping 12 letters: 0 ink pixels on their line, 3047 under it, <code>textContent</code> unchanged.</td></tr>
<tr><td>The canvas outside the element's ink</td><td>transparent</td><td>An element with no background leaves the canvas transparent between glyphs, so a piece of the canvas is a letter with nothing behind it.</td></tr>
<tr><td>288 letters per frame from a snapshot (<code>drawImage()</code>) against from the live element (<code>drawElementImage()</code> through a clip, once per letter)</td><td>49.6 ms against 442.3 ms</td><td>Software renderer, and both numbers include <code>getImageData()</code> of the whole canvas. The live route replays the element's paint record once per letter.</td></tr>
<tr><td>A bar drawn over a range after the element (<code>/redact/</code>)</td><td>covers every pixel</td><td>10560 canvas pixels inside the range's rectangle, all the bar colour.</td></tr>
<tr><td>The DOM after a canvas redaction</td><td>still has the text</td><td><code>textContent</code>, <code>Range.toString()</code> and copy return it. The page's copy handler and "Remove the text from the DOM" are the two ways it offers to close that.</td></tr>
<tr><td><code>ctx.filter = 'blur()'</code> on <code>drawElementImage()</code></td><td>works</td><td>The blur style changed 9196 pixels inside the range and 0 outside. Filter lengths are canvas pixels, so the page multiplies by the canvas scale.</td></tr>
<tr><td><code>drawImage(canvas)</code> with the canvas itself as the source, after <code>drawElementImage()</code></td><td>works</td><td>The pixel style reads the part of the canvas it replaces. The canvas is not tainted by same-origin element content.</td></tr>
<tr><td>Replacing characters in the DOM under a Custom Highlight range</td><td>offsets stay valid</td><td>Setting <code>node.data</code> collapses live ranges in that node, so the page rebuilds its ranges from stored offsets. 10 characters replaced, the range kept one rectangle.</td></tr>
<tr><td>One element drawn twice in a frame at different sizes (<code>/selection-heat/</code>)</td><td>works</td><td>The minimap is the article at scale 0.169 in the fixture: 478 text pixels and 57 heat pixels at the scaled position.</td></tr>
<tr><td>A minimap in a second canvas</td><td>not possible</td><td>An element is drawn only by its own canvas (known from the first findings), so the minimap is inside the article's canvas, in a column the article reserves with padding.</td></tr>
<tr><td><code>document.caretPositionFromPoint()</code> on text drawn by the canvas</td><td>works</td><td>Returned offset 7 for a point on the eighth character.</td></tr>
<tr><td>An element drawn at four times its layout size (<code>/share-card/</code>)</td><td>drawn again, not stretched</td><td>A 1 px line became 4 black pixels with 0 grey pixels beside it.</td></tr>
<tr><td><code>canvas.toBlob()</code> after <code>drawElementImage()</code></td><td>works</td><td>PNGs of 1200×630, 1080×1080 and 1080×1920 decoded at those sizes.</td></tr>
<tr><td><code>scrollHeight</code> and <code>clientHeight</code> on a canvas child</td><td>work</td><td>They drive the card's type size: 67.5 px for 3 words, smaller for 420 characters, both fit.</td></tr>
<tr><td>A canvas child wider than the canvas element</td><td>works</td><td>The figure is 600 px wide in a canvas shown about 396 px wide. The picture is complete.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li><code>shared/style.css</code> gives <code>figure</code> a <code>max-width: 100%</code>, and a canvas child obeys it against the canvas's CSS width. The share card was laid out 396 px wide and drawn stretched until the figure got <code>max-width: none</code>.</li>
<li>After a 2D <code>drawElementImage()</code> with a size different from the layout size, <code>getBoundingClientRect()</code> of the element reports the drawn size (396×208 for a 600×315 figure). Layout sizes come from <code>offsetWidth</code> and <code>clientHeight</code>.</li>
<li><code>s.rects</code> in a <code>&lt;selection-fx&gt;</code> effect holds the selection and the <code>highlight</code> attribute's ranges together. An effect that draws the two differently reads <code>s.marked</code> for the ranges and uses <code>s.rects</code> only while something is selected.</li>
<li>Fitting type by <code>scrollHeight</code> and then changing <code>line-height</code> undoes the fit. The line height is fixed in CSS.</li>
<li>Reported from Paul's phone (Android Chrome 159) through the coordinator on 2026-11-21, not measured here: a drawable 2D canvas that is read back with <code>getImageData()</code> (with <code>willReadFrequently</code>) lost every 2D context on the page. These five pages never call <code>getImageData()</code> on a drawable canvas. <code>snapshot()</code> and <code>copyCanvas()</code> in <code>lib/selection-tools.js</code> copy the canvas to an <code>OffscreenCanvas</code> with <code>drawImage()</code> and read the copy.</li>
<li>The site menu stays at the top of the window, so a minimap that follows the scroll is placed 64 px below the window's top edge.</li>
<li>The article's own minimap column is part of the element, so the minimap shows an empty strip at its right edge.</li></ul>
<h4>Not verified</h4>
<ul><li>Touch on all five pages: long-press selection, the Android handles, the automatic drop 0.7 s after the last selection change on <code>/selection-glyphs/</code>, and dragging in the minimap column on <code>/selection-heat/</code>. Needs a phone.</li>
<li>Frame rate with several hundred loose letters, and how closely the minimap follows a touch scroll. Needs a phone.</li>
<li><code>navigator.share()</code> with a PNG file and <code>navigator.clipboard.write()</code> with a PNG on <code>/share-card/</code>. The headless browser has no share sheet and no clipboard permission. Press Share and Copy picture on a phone.</li>
<li>What find-in-page and TalkBack report for a range covered on <code>/redact/</code>. Both read the DOM, so the expected answer is the original text until it is removed.</li>
<li>Two people on two devices on <code>/selection-peers/</code>. The page has a <code>BroadcastChannel</code> only, so it reaches tabs and frames of one browser. A relay server would carry the same message.</li></ul>
<h4>Ideas not built</h4>
<ul><li>A relay (Durable Object or WebRTC data channel) so <code>/selection-peers/</code> works between devices, and readers' carets as well as selections.</li>
<li>Letters on <code>/selection-glyphs/</code> that collide with each other and can be pushed with a finger.</li>
<li>Redaction that also exports a PDF, and a "peek" that shows a range while it is pressed.</li>
<li>Heat collected from real visitors, and a minimap for a whole page of several canvases.</li>
<li>Share cards with a QR code of a text-fragment link to the passage.</li></ul>
<h4>For the index</h4>
<ul><li>Text and ranges: any <code>Range</code> has rectangles at the drawn position whether or not it is selected; one <code>Range</code> per character gives per-letter boxes (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: <code>ctx.filter</code>, <code>clip('evenodd')</code> and a self-sourced <code>drawImage()</code> all apply to <code>drawElementImage()</code> output (<code>/redact/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: an element drawn larger than its layout is re-rasterised, and one element can be drawn several times per frame at different sizes (<code>/share-card/</code>, <code>/selection-heat/</code>).</li>
<li>Export: <code>toBlob()</code> and <code>getImageData()</code> work after <code>drawElementImage()</code> of same-origin content (<code>/share-card/</code>, <code>/redact/</code>).</li>
<li>Layout: <code>scrollHeight</code> works on canvas children; <code>max-width: 100%</code> on a canvas child resolves against the canvas's CSS width (<code>/share-card/</code>).</li>
<li>Accessibility and privacy: drawing over text in the canvas hides nothing from the DOM (<code>/redact/</code>).</li></ul>
<p><a href="https://html-in-canvas.page/selection-glyphs/">Open Selected letters as particles</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A heat map and minimap of selections</title>
<link>https://html-in-canvas.page/selection-heat/</link>
<guid isPermaLink="true">https://html-in-canvas.page/selection-heat/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Range.getClientRects()</category>
<category>drawElementImage</category>
<category>caretPositionFromPoint()</category>
<description>An article in a canvas coloured by how often each part has been selected, with the whole article drawn a second time as a minimap that stays in view. Starts with 40 simulated readers and adds your own selections.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/selection-heat/"><img src="https://html-in-canvas.page/selection-heat/social.jpg" width="1200" height="630" alt="The page &quot;A heat map and minimap of selections&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas colour text by how often it was selected and draw the same element again as a minimap?</p>
<p><strong>Short answer:</strong> Yes. One element can be drawn twice in a frame at different sizes, but only inside its own canvas.</p>
<p>
An article drawn by a canvas and coloured by how often each part has been selected. It starts with the selections of 40 simulated readers. Every selection you make is added after you stop changing it. The column at the right is the whole article drawn small with the same colours: drag in it to scroll, and tap a sentence in the article to read its count.
</p>
<h3>How it works</h3>
<p>
The page keeps one counter per character of the article. A selection is turned into a start and an end offset and adds one to each counter between them. Before drawing, the counters are grouped into runs of characters with the same level, and each run is measured with <code>Range.getClientRects()</code>. The canvas fills those rectangles, draws the article over them, and then draws the article a second time into a rectangle 54 pixels wide. An element's picture can only be drawn into the canvas it belongs to, which is why the minimap is inside the article's own canvas and not in a separate one beside it. The counters are saved in <code>localStorage</code> in this browser. Nothing is sent anywhere.
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.</p>
<ul>
<li><strong>One element can be drawn twice in a frame at different sizes.</strong> The minimap is the article at about a tenth of its width, drawn from the same paint record as the full-size text. Lines of text become grey strokes and the heat colours stay readable.</li>
<li><strong>The minimap has to share the article's canvas.</strong> An element is drawn only by its own canvas, so a second canvas beside the article can't draw it.</li>
<li><strong>Heat is drawn from ranges, not from wrapped elements.</strong> Runs of equal level are measured again when the width changes. The article's DOM is the same with and without the heat.</li>
<li><strong><code>document.caretPositionFromPoint()</code> on the canvas gives the character under a tap</strong>, which the page turns into an offset to look up the count (checked below).</li>
<li><strong>A minimap that stays in view needs a redraw on scroll.</strong> The page listens for <code>scroll</code> and draws the canvas again with the new position. The picture is one frame behind the scroll.</li>
</ul>
<p><strong>Not verified:</strong> how smoothly the minimap follows a touch scroll on a phone, dragging in the column by touch, and selections collected from real readers (this page has no server).</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/selection.md">findings/selection.md</a> in the repository.</p>
<h3>Five pages drawn from ranges (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>, <code>/redact/</code>, <code>/selection-heat/</code>, <code>/share-card/</code>)</h3>
<p>Measured in headless Chromium 157 (Linux, software renderer, device scale factor 2) on 2026-11-21. Each row is a live check on the page named. The first four pages are 2D effects registered on <code>&lt;selection-fx&gt;</code> with <code>defineSelectionEffect()</code> from their own modules. Shared helpers are in <code>lib/selection-tools.js</code> and shared styles in <code>lib/selection-article.css</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Rectangles of a range that is not selected (<code>/selection-peers/</code>)</td><td>works</td><td><code>Range.getClientRects()</code> needs no selection. A canvas draws any number of other readers' ranges with no change to the DOM or to the document's selection (HTML and selection compared before and after).</td></tr>
<tr><td>A selection sent as two offsets into <code>textContent</code> and rebuilt in another document</td><td>works</td><td>Round trip checked across an inline element. A message on a <code>BroadcastChannel</code> arrived in 25 ms and the range was drawn 48.2 px wide for 4 characters of 12 px.</td></tr>
<tr><td>A same-origin frame as a second reader</td><td>works</td><td>Each document has its own selection, so selecting in the frame does not clear the page's selection. Checked with a script, not a live check: both selections were held at once and each side drew the other's range.</td></tr>
<tr><td>One <code>Range</code> per character (<code>/selection-glyphs/</code>)</td><td>works</td><td>12 rectangles for 12 letters, each 12.0 px wide in a 20 px monospace font. The box is the advance width and the line's text height, not the ink.</td></tr>
<tr><td>Letters taken out of the element's picture with an even-odd clip and drawn elsewhere</td><td>works</td><td>After dropping 12 letters: 0 ink pixels on their line, 3047 under it, <code>textContent</code> unchanged.</td></tr>
<tr><td>The canvas outside the element's ink</td><td>transparent</td><td>An element with no background leaves the canvas transparent between glyphs, so a piece of the canvas is a letter with nothing behind it.</td></tr>
<tr><td>288 letters per frame from a snapshot (<code>drawImage()</code>) against from the live element (<code>drawElementImage()</code> through a clip, once per letter)</td><td>49.6 ms against 442.3 ms</td><td>Software renderer, and both numbers include <code>getImageData()</code> of the whole canvas. The live route replays the element's paint record once per letter.</td></tr>
<tr><td>A bar drawn over a range after the element (<code>/redact/</code>)</td><td>covers every pixel</td><td>10560 canvas pixels inside the range's rectangle, all the bar colour.</td></tr>
<tr><td>The DOM after a canvas redaction</td><td>still has the text</td><td><code>textContent</code>, <code>Range.toString()</code> and copy return it. The page's copy handler and "Remove the text from the DOM" are the two ways it offers to close that.</td></tr>
<tr><td><code>ctx.filter = 'blur()'</code> on <code>drawElementImage()</code></td><td>works</td><td>The blur style changed 9196 pixels inside the range and 0 outside. Filter lengths are canvas pixels, so the page multiplies by the canvas scale.</td></tr>
<tr><td><code>drawImage(canvas)</code> with the canvas itself as the source, after <code>drawElementImage()</code></td><td>works</td><td>The pixel style reads the part of the canvas it replaces. The canvas is not tainted by same-origin element content.</td></tr>
<tr><td>Replacing characters in the DOM under a Custom Highlight range</td><td>offsets stay valid</td><td>Setting <code>node.data</code> collapses live ranges in that node, so the page rebuilds its ranges from stored offsets. 10 characters replaced, the range kept one rectangle.</td></tr>
<tr><td>One element drawn twice in a frame at different sizes (<code>/selection-heat/</code>)</td><td>works</td><td>The minimap is the article at scale 0.169 in the fixture: 478 text pixels and 57 heat pixels at the scaled position.</td></tr>
<tr><td>A minimap in a second canvas</td><td>not possible</td><td>An element is drawn only by its own canvas (known from the first findings), so the minimap is inside the article's canvas, in a column the article reserves with padding.</td></tr>
<tr><td><code>document.caretPositionFromPoint()</code> on text drawn by the canvas</td><td>works</td><td>Returned offset 7 for a point on the eighth character.</td></tr>
<tr><td>An element drawn at four times its layout size (<code>/share-card/</code>)</td><td>drawn again, not stretched</td><td>A 1 px line became 4 black pixels with 0 grey pixels beside it.</td></tr>
<tr><td><code>canvas.toBlob()</code> after <code>drawElementImage()</code></td><td>works</td><td>PNGs of 1200×630, 1080×1080 and 1080×1920 decoded at those sizes.</td></tr>
<tr><td><code>scrollHeight</code> and <code>clientHeight</code> on a canvas child</td><td>work</td><td>They drive the card's type size: 67.5 px for 3 words, smaller for 420 characters, both fit.</td></tr>
<tr><td>A canvas child wider than the canvas element</td><td>works</td><td>The figure is 600 px wide in a canvas shown about 396 px wide. The picture is complete.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li><code>shared/style.css</code> gives <code>figure</code> a <code>max-width: 100%</code>, and a canvas child obeys it against the canvas's CSS width. The share card was laid out 396 px wide and drawn stretched until the figure got <code>max-width: none</code>.</li>
<li>After a 2D <code>drawElementImage()</code> with a size different from the layout size, <code>getBoundingClientRect()</code> of the element reports the drawn size (396×208 for a 600×315 figure). Layout sizes come from <code>offsetWidth</code> and <code>clientHeight</code>.</li>
<li><code>s.rects</code> in a <code>&lt;selection-fx&gt;</code> effect holds the selection and the <code>highlight</code> attribute's ranges together. An effect that draws the two differently reads <code>s.marked</code> for the ranges and uses <code>s.rects</code> only while something is selected.</li>
<li>Fitting type by <code>scrollHeight</code> and then changing <code>line-height</code> undoes the fit. The line height is fixed in CSS.</li>
<li>Reported from Paul's phone (Android Chrome 159) through the coordinator on 2026-11-21, not measured here: a drawable 2D canvas that is read back with <code>getImageData()</code> (with <code>willReadFrequently</code>) lost every 2D context on the page. These five pages never call <code>getImageData()</code> on a drawable canvas. <code>snapshot()</code> and <code>copyCanvas()</code> in <code>lib/selection-tools.js</code> copy the canvas to an <code>OffscreenCanvas</code> with <code>drawImage()</code> and read the copy.</li>
<li>The site menu stays at the top of the window, so a minimap that follows the scroll is placed 64 px below the window's top edge.</li>
<li>The article's own minimap column is part of the element, so the minimap shows an empty strip at its right edge.</li></ul>
<h4>Not verified</h4>
<ul><li>Touch on all five pages: long-press selection, the Android handles, the automatic drop 0.7 s after the last selection change on <code>/selection-glyphs/</code>, and dragging in the minimap column on <code>/selection-heat/</code>. Needs a phone.</li>
<li>Frame rate with several hundred loose letters, and how closely the minimap follows a touch scroll. Needs a phone.</li>
<li><code>navigator.share()</code> with a PNG file and <code>navigator.clipboard.write()</code> with a PNG on <code>/share-card/</code>. The headless browser has no share sheet and no clipboard permission. Press Share and Copy picture on a phone.</li>
<li>What find-in-page and TalkBack report for a range covered on <code>/redact/</code>. Both read the DOM, so the expected answer is the original text until it is removed.</li>
<li>Two people on two devices on <code>/selection-peers/</code>. The page has a <code>BroadcastChannel</code> only, so it reaches tabs and frames of one browser. A relay server would carry the same message.</li></ul>
<h4>Ideas not built</h4>
<ul><li>A relay (Durable Object or WebRTC data channel) so <code>/selection-peers/</code> works between devices, and readers' carets as well as selections.</li>
<li>Letters on <code>/selection-glyphs/</code> that collide with each other and can be pushed with a finger.</li>
<li>Redaction that also exports a PDF, and a "peek" that shows a range while it is pressed.</li>
<li>Heat collected from real visitors, and a minimap for a whole page of several canvases.</li>
<li>Share cards with a QR code of a text-fragment link to the passage.</li></ul>
<h4>For the index</h4>
<ul><li>Text and ranges: any <code>Range</code> has rectangles at the drawn position whether or not it is selected; one <code>Range</code> per character gives per-letter boxes (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: <code>ctx.filter</code>, <code>clip('evenodd')</code> and a self-sourced <code>drawImage()</code> all apply to <code>drawElementImage()</code> output (<code>/redact/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: an element drawn larger than its layout is re-rasterised, and one element can be drawn several times per frame at different sizes (<code>/share-card/</code>, <code>/selection-heat/</code>).</li>
<li>Export: <code>toBlob()</code> and <code>getImageData()</code> work after <code>drawElementImage()</code> of same-origin content (<code>/share-card/</code>, <code>/redact/</code>).</li>
<li>Layout: <code>scrollHeight</code> works on canvas children; <code>max-width: 100%</code> on a canvas child resolves against the canvas's CSS width (<code>/share-card/</code>).</li>
<li>Accessibility and privacy: drawing over text in the canvas hides nothing from the DOM (<code>/redact/</code>).</li></ul>
<p><a href="https://html-in-canvas.page/selection-heat/">Open A heat map and minimap of selections</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Other people's selections</title>
<link>https://html-in-canvas.page/selection-peers/</link>
<guid isPermaLink="true">https://html-in-canvas.page/selection-peers/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Range.getClientRects()</category>
<category>BroadcastChannel</category>
<category>drawElementImage</category>
<description>An article in a canvas with other readers' selections drawn into it: a colour, a bar at the moving end and a name flag for each. Selections travel as text offsets over a BroadcastChannel between the page, a frame and other tabs.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/selection-peers/"><img src="https://html-in-canvas.page/selection-peers/social.jpg" width="1200" height="630" alt="The page &quot;Other people's selections&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas show the selections of several other readers in its text without changing the DOM or the reader's own selection?</p>
<p><strong>Short answer:</strong> Yes. Any Range has rectangles, selected or not.</p>
<p>
An article drawn by a canvas, with the selections of other readers drawn into it. Two simulated readers select sentences. Select some text yourself, then press “Show a second reader” to get a second copy of the page in a frame: a selection made in either copy appears in the other. A copy open in another tab joins too.
</p>
<h3>How it works</h3>
<p>
Each copy of the page listens for <code>selectionchange</code>, converts its selection to a start and an end offset in the article's text and posts them on a <code>BroadcastChannel</code>. A copy that receives offsets builds a <code>Range</code> from them, reads <code>getClientRects()</code> for each text node in it, and draws the rectangles in the canvas before the text and the flag after it. The receiving page's DOM and its own selection don't change. Tabs and frames of one origin share the channel. Between two people the same message would go through a server.
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.</p>
<ul>
<li><strong>A range that isn't selected still has rectangles.</strong> <code>Range.getClientRects()</code> works for any range, so a canvas can draw any number of other readers. The receiving document's selection and DOM aren't changed (checked below).</li>
<li><strong>Offsets into <code>textContent</code> are enough to send a selection</strong> between copies whose text is the same. They survive different line breaks, widths and fonts, because each copy measures its own rectangles. They don't survive an edit of the text.</li>
<li><strong>A frame of the same origin is a second reader.</strong> Each document has its own selection, so selecting in the frame doesn't clear the selection in the page, and both are sent.</li>
<li><strong>What the canvas adds over <code>::highlight()</code>:</strong> a Custom Highlight could colour another reader's range with no canvas. It can't draw the name flag, the bar at the moving end or an animation between two positions.</li>
</ul>
<p><strong>Not verified:</strong> selecting by touch in the page and in the frame on a phone, and two phones through a server (this page has no server, only a channel inside one browser).</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/selection.md">findings/selection.md</a> in the repository.</p>
<h3>Five pages drawn from ranges (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>, <code>/redact/</code>, <code>/selection-heat/</code>, <code>/share-card/</code>)</h3>
<p>Measured in headless Chromium 157 (Linux, software renderer, device scale factor 2) on 2026-11-21. Each row is a live check on the page named. The first four pages are 2D effects registered on <code>&lt;selection-fx&gt;</code> with <code>defineSelectionEffect()</code> from their own modules. Shared helpers are in <code>lib/selection-tools.js</code> and shared styles in <code>lib/selection-article.css</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Rectangles of a range that is not selected (<code>/selection-peers/</code>)</td><td>works</td><td><code>Range.getClientRects()</code> needs no selection. A canvas draws any number of other readers' ranges with no change to the DOM or to the document's selection (HTML and selection compared before and after).</td></tr>
<tr><td>A selection sent as two offsets into <code>textContent</code> and rebuilt in another document</td><td>works</td><td>Round trip checked across an inline element. A message on a <code>BroadcastChannel</code> arrived in 25 ms and the range was drawn 48.2 px wide for 4 characters of 12 px.</td></tr>
<tr><td>A same-origin frame as a second reader</td><td>works</td><td>Each document has its own selection, so selecting in the frame does not clear the page's selection. Checked with a script, not a live check: both selections were held at once and each side drew the other's range.</td></tr>
<tr><td>One <code>Range</code> per character (<code>/selection-glyphs/</code>)</td><td>works</td><td>12 rectangles for 12 letters, each 12.0 px wide in a 20 px monospace font. The box is the advance width and the line's text height, not the ink.</td></tr>
<tr><td>Letters taken out of the element's picture with an even-odd clip and drawn elsewhere</td><td>works</td><td>After dropping 12 letters: 0 ink pixels on their line, 3047 under it, <code>textContent</code> unchanged.</td></tr>
<tr><td>The canvas outside the element's ink</td><td>transparent</td><td>An element with no background leaves the canvas transparent between glyphs, so a piece of the canvas is a letter with nothing behind it.</td></tr>
<tr><td>288 letters per frame from a snapshot (<code>drawImage()</code>) against from the live element (<code>drawElementImage()</code> through a clip, once per letter)</td><td>49.6 ms against 442.3 ms</td><td>Software renderer, and both numbers include <code>getImageData()</code> of the whole canvas. The live route replays the element's paint record once per letter.</td></tr>
<tr><td>A bar drawn over a range after the element (<code>/redact/</code>)</td><td>covers every pixel</td><td>10560 canvas pixels inside the range's rectangle, all the bar colour.</td></tr>
<tr><td>The DOM after a canvas redaction</td><td>still has the text</td><td><code>textContent</code>, <code>Range.toString()</code> and copy return it. The page's copy handler and "Remove the text from the DOM" are the two ways it offers to close that.</td></tr>
<tr><td><code>ctx.filter = 'blur()'</code> on <code>drawElementImage()</code></td><td>works</td><td>The blur style changed 9196 pixels inside the range and 0 outside. Filter lengths are canvas pixels, so the page multiplies by the canvas scale.</td></tr>
<tr><td><code>drawImage(canvas)</code> with the canvas itself as the source, after <code>drawElementImage()</code></td><td>works</td><td>The pixel style reads the part of the canvas it replaces. The canvas is not tainted by same-origin element content.</td></tr>
<tr><td>Replacing characters in the DOM under a Custom Highlight range</td><td>offsets stay valid</td><td>Setting <code>node.data</code> collapses live ranges in that node, so the page rebuilds its ranges from stored offsets. 10 characters replaced, the range kept one rectangle.</td></tr>
<tr><td>One element drawn twice in a frame at different sizes (<code>/selection-heat/</code>)</td><td>works</td><td>The minimap is the article at scale 0.169 in the fixture: 478 text pixels and 57 heat pixels at the scaled position.</td></tr>
<tr><td>A minimap in a second canvas</td><td>not possible</td><td>An element is drawn only by its own canvas (known from the first findings), so the minimap is inside the article's canvas, in a column the article reserves with padding.</td></tr>
<tr><td><code>document.caretPositionFromPoint()</code> on text drawn by the canvas</td><td>works</td><td>Returned offset 7 for a point on the eighth character.</td></tr>
<tr><td>An element drawn at four times its layout size (<code>/share-card/</code>)</td><td>drawn again, not stretched</td><td>A 1 px line became 4 black pixels with 0 grey pixels beside it.</td></tr>
<tr><td><code>canvas.toBlob()</code> after <code>drawElementImage()</code></td><td>works</td><td>PNGs of 1200×630, 1080×1080 and 1080×1920 decoded at those sizes.</td></tr>
<tr><td><code>scrollHeight</code> and <code>clientHeight</code> on a canvas child</td><td>work</td><td>They drive the card's type size: 67.5 px for 3 words, smaller for 420 characters, both fit.</td></tr>
<tr><td>A canvas child wider than the canvas element</td><td>works</td><td>The figure is 600 px wide in a canvas shown about 396 px wide. The picture is complete.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li><code>shared/style.css</code> gives <code>figure</code> a <code>max-width: 100%</code>, and a canvas child obeys it against the canvas's CSS width. The share card was laid out 396 px wide and drawn stretched until the figure got <code>max-width: none</code>.</li>
<li>After a 2D <code>drawElementImage()</code> with a size different from the layout size, <code>getBoundingClientRect()</code> of the element reports the drawn size (396×208 for a 600×315 figure). Layout sizes come from <code>offsetWidth</code> and <code>clientHeight</code>.</li>
<li><code>s.rects</code> in a <code>&lt;selection-fx&gt;</code> effect holds the selection and the <code>highlight</code> attribute's ranges together. An effect that draws the two differently reads <code>s.marked</code> for the ranges and uses <code>s.rects</code> only while something is selected.</li>
<li>Fitting type by <code>scrollHeight</code> and then changing <code>line-height</code> undoes the fit. The line height is fixed in CSS.</li>
<li>Reported from Paul's phone (Android Chrome 159) through the coordinator on 2026-11-21, not measured here: a drawable 2D canvas that is read back with <code>getImageData()</code> (with <code>willReadFrequently</code>) lost every 2D context on the page. These five pages never call <code>getImageData()</code> on a drawable canvas. <code>snapshot()</code> and <code>copyCanvas()</code> in <code>lib/selection-tools.js</code> copy the canvas to an <code>OffscreenCanvas</code> with <code>drawImage()</code> and read the copy.</li>
<li>The site menu stays at the top of the window, so a minimap that follows the scroll is placed 64 px below the window's top edge.</li>
<li>The article's own minimap column is part of the element, so the minimap shows an empty strip at its right edge.</li></ul>
<h4>Not verified</h4>
<ul><li>Touch on all five pages: long-press selection, the Android handles, the automatic drop 0.7 s after the last selection change on <code>/selection-glyphs/</code>, and dragging in the minimap column on <code>/selection-heat/</code>. Needs a phone.</li>
<li>Frame rate with several hundred loose letters, and how closely the minimap follows a touch scroll. Needs a phone.</li>
<li><code>navigator.share()</code> with a PNG file and <code>navigator.clipboard.write()</code> with a PNG on <code>/share-card/</code>. The headless browser has no share sheet and no clipboard permission. Press Share and Copy picture on a phone.</li>
<li>What find-in-page and TalkBack report for a range covered on <code>/redact/</code>. Both read the DOM, so the expected answer is the original text until it is removed.</li>
<li>Two people on two devices on <code>/selection-peers/</code>. The page has a <code>BroadcastChannel</code> only, so it reaches tabs and frames of one browser. A relay server would carry the same message.</li></ul>
<h4>Ideas not built</h4>
<ul><li>A relay (Durable Object or WebRTC data channel) so <code>/selection-peers/</code> works between devices, and readers' carets as well as selections.</li>
<li>Letters on <code>/selection-glyphs/</code> that collide with each other and can be pushed with a finger.</li>
<li>Redaction that also exports a PDF, and a "peek" that shows a range while it is pressed.</li>
<li>Heat collected from real visitors, and a minimap for a whole page of several canvases.</li>
<li>Share cards with a QR code of a text-fragment link to the passage.</li></ul>
<h4>For the index</h4>
<ul><li>Text and ranges: any <code>Range</code> has rectangles at the drawn position whether or not it is selected; one <code>Range</code> per character gives per-letter boxes (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: <code>ctx.filter</code>, <code>clip('evenodd')</code> and a self-sourced <code>drawImage()</code> all apply to <code>drawElementImage()</code> output (<code>/redact/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: an element drawn larger than its layout is re-rasterised, and one element can be drawn several times per frame at different sizes (<code>/share-card/</code>, <code>/selection-heat/</code>).</li>
<li>Export: <code>toBlob()</code> and <code>getImageData()</code> work after <code>drawElementImage()</code> of same-origin content (<code>/share-card/</code>, <code>/redact/</code>).</li>
<li>Layout: <code>scrollHeight</code> works on canvas children; <code>max-width: 100%</code> on a canvas child resolves against the canvas's CSS width (<code>/share-card/</code>).</li>
<li>Accessibility and privacy: drawing over text in the canvas hides nothing from the DOM (<code>/redact/</code>).</li></ul>
<p><a href="https://html-in-canvas.page/selection-peers/">Open Other people's selections</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Text selection effects</title>
<link>https://html-in-canvas.page/selection/</link>
<guid isPermaLink="true">https://html-in-canvas.page/selection/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Range.getClientRects()</category>
<category>::selection</category>
<category>CSS Custom Highlight</category>
<description>Select text that a canvas draws and the canvas draws the highlight: marker strokes, lifted lines, a loupe, trails, glow, fire and a wave, from Range.getClientRects(). Records what the browser paints for a selection inside a canvas.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/selection/"><img src="https://html-in-canvas.page/selection/social.jpg" width="1200" height="630" alt="The page &quot;Text selection effects&quot;"></a></p>
<p><strong>Question:</strong> When text inside a canvas is selected, what does the browser draw, and can the canvas draw its own highlight from the rectangles of the selected text?</p>
<p>
The text below is HTML drawn by a canvas. Selecting it is done by the browser as usual, including the Android handles and the copy menu.
The page reads the rectangles of the selected text and the canvas draws the highlight. Select some text, then change the effect.
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21. The last list says what that browser couldn't show.</p>
<ul>
<li><strong>The browser's selection highlight is part of the element's picture.</strong> It is in the pixels that <code>drawElementImage()</code>, <code>texElementSubImage2D()</code> and a canvas read-back return, in the active colour, and it's transformed with the element.</li>
<li><strong><code>paint</code> fires on every change of the selection</strong>, because the highlight changes the element's rendering. A 30-step mouse drag fired 19 paint events. No <code>selectionchange</code> listener is needed just to redraw. One is needed to measure.</li>
<li><strong><code>::selection</code> styles apply.</strong> A custom background and colour are drawn. <code>background-color: transparent</code> with no <code>color</code> leaves the picture identical to the unselected one, pixel for pixel, while the selection still exists. That's how <code>&lt;selection-fx&gt;</code> removes the browser's highlight and draws its own.</li>
<li><strong><code>::highlight()</code> from the CSS Custom Highlight API is drawn too</strong>, and changing the registry fires <code>paint</code>. A Highlight with no style is invisible and still gives ranges to measure, so search matches can drive the same effects (the Find box above).</li>
<li><strong><code>Range.getClientRects()</code> follows the drawn position</strong>, to within a pixel, when the element is drawn with a translation. The rectangles are in page coordinates as usual.</li>
<li><strong>Under a rotation the rectangles are bounding boxes.</strong> There is no quad version (<code>getBoxQuads()</code> isn't in Chromium), so the shape of a rotated line is lost. <code>updateElementGeometry(el, { canvasTransform: identity })</code> changes what <code>getClientRects()</code> returns synchronously, so measuring under the identity and restoring the transform in the same task gives element-local rectangles without a visible change.</li>
<li><strong><code>range.getClientRects()</code> on a whole selection also returns the boxes of block elements</strong> that are fully inside it, which would highlight a whole paragraph box. Measuring one range per text node avoids that.</li>
<li><strong>Hit testing for selection follows the drawn geometry.</strong> Mouse drag, double click and <code>caretPositionFromPoint()</code> pick the right characters on an element drawn rotated and scaled. Dragging from one drawable element to another, and from outside the canvas into it, selects across them in document order.</li>
<li><strong>Selection doesn't cross into a <code>contenteditable</code> child</strong> when the drag starts outside it. That's the usual editing-boundary rule, not something the canvas adds.</li>
<li><strong>The caret is drawn, and each blink fires <code>paint</code></strong> (4 events in 2.2 seconds with a focused editable element). A shader effect therefore uploads the element's texture twice a second while a caret is showing.</li>
<li><strong>Text selected inside an <code>&lt;input&gt;</code> or <code>&lt;textarea&gt;</code> is highlighted in the picture but can't be measured.</strong> <code>getSelection()</code> has no range inside the control and there's no rectangle API for <code>selectionStart</code>/<code>selectionEnd</code>, so these effects don't apply to form controls.</li>
<li><strong>Releasing a WebGL context can crash the tab.</strong> <code>WEBGL_lose_context.loseContext()</code> on a drawable canvas that is still in the document and holds an element texture crashed the renderer in Chromium 157. Removing the canvas from the document first does not. A WebGL canvas also reports loss with <code>webglcontextlost</code>, not the <code>contextlost</code> event of a 2D canvas.</li>
<li><strong>Effects are visual only.</strong> <code>&lt;selection-fx&gt;</code> leaves the element's geometry at its layout position, so the caret, the handles and hit testing stay on the line even while the wave effect moves the glyphs by 4 px.</li>
<li><strong>A shader needs to know which pixels are glyphs.</strong> The slotted content has a transparent background, so the element texture's alpha is the glyph coverage. For text on its own opaque background the shaders compare against <code>--selection-fx-bg</code>.</li>
<li><strong>The rectangles reach a shader as a mask texture</strong> drawn with a 2D <code>OffscreenCanvas</code>, not as a uniform array, so the count of lines isn't limited and the mask can carry a blurred copy and a fading history at no shader cost.</li>
</ul>
<p><strong>Not verified here, needs a real device:</strong></p>
<ul>
<li><strong>Touch selection.</strong> Long press didn't select anything in the headless test browser, inside or outside a canvas, so press and hold, the Android handles and the copy menu are untested. Things to look at on a phone: whether the handles appear at the drawn position of a rotated line, whether they still appear when <code>::selection</code> is transparent, and whether the loupe effect is hidden under the finger or under Chrome's own magnifier.</li>
<li><strong><code>::target-text</code> (text fragment links), find-in-page marks and spelling marks.</strong> The headless browser showed none of them even outside a canvas. The explainer says spelling marks and find-in-page marks are left out of an element's picture for privacy. <a href="https://html-in-canvas.page/selection/#:~:text=the%20way%20they%20do%20in%20any%20paragraph">This link</a> scrolls to a text fragment in the demo above: if the browser marks it, the mark is either in the canvas (drawn with the text) or missing.</li>
<li><strong>Why a canvas lost its context on an Android phone.</strong> The first version of this page started on the glow shader and ran its checks on load, and on Chrome 159 the demo was a white box with a broken-picture icon. The cause isn't identified. The page now starts on a 2D effect, creates GPU contexts only when a shader effect is picked or the checks are started, and <code>&lt;selection-fx&gt;</code> moves its content to a new 2D canvas when its canvas loses its context or shows no picture. The line under the demo says when that happened.</li>
<li><strong>WebGPU on screen.</strong> The WGSL of each effect compiles here and an off-screen WebGPU frame is compared with the WebGL one in the checks. The software adapter can't show a WebGPU canvas, so the on-screen route is untested.</li>
<li><strong>Speed on a phone.</strong> Glow takes 24 texture samples per pixel and burn 16.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/selection.md">findings/selection.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 (Linux, software renderer) on 2026-11-21. The page's live checks repeat the rows that do not need focus.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>The browser's selection highlight in the pixels of <code>drawElementImage()</code>, <code>texElementSubImage2D()</code> and a read-back</td><td>works</td><td>The highlight is part of the element's paint record, in the active colour, and is transformed with the element.</td></tr>
<tr><td><code>paint</code> fires when the selection changes</td><td>works</td><td>No <code>requestPaint()</code> needed. A 30-step mouse drag fired 19 paint events.</td></tr>
<tr><td><code>::selection</code> colours</td><td>works</td><td>A custom background and colour are drawn. <code>background-color: transparent</code> with no <code>color</code> gives a picture identical to the unselected one while the selection still exists.</td></tr>
<tr><td><code>::highlight()</code> (CSS Custom Highlight API)</td><td>works</td><td>Drawn, and setting or clearing the registry fires <code>paint</code>. A Highlight with no style gives ranges to measure and draws nothing.</td></tr>
<tr><td><code>Range.getClientRects()</code> against the drawn highlight, element drawn with a translation</td><td>works</td><td>Within 1 px. Rectangles are in page coordinates and follow the drawn position.</td></tr>
<tr><td><code>Range.getClientRects()</code> on an element drawn rotated</td><td>fails</td><td>Returns the upright bounding box of each rotated line (72×24 becomes 76×38 at 0.2 rad). <code>getBoxQuads()</code> is not in Chromium.</td></tr>
<tr><td><code>updateElementGeometry(identity)</code>, measure, restore, in one task</td><td>works</td><td><code>getClientRects()</code> follows the geometry synchronously, so this gives element-local rectangles with no visible change. Note that <code>geometryUnit()</code> in <code>lib/surface.js</code> applies the identity itself.</td></tr>
<tr><td><code>range.getClientRects()</code> on a selection that spans paragraphs</td><td>misleading</td><td>It also returns the boxes of block elements fully inside the range. <code>textRects()</code> uses one Range per text node.</td></tr>
<tr><td>Mouse drag, double click and <code>caretPositionFromPoint()</code> on an element drawn rotated and scaled</td><td>works</td><td>Selection hit testing follows the drawn geometry. Also checked at device scale factor 2.625.</td></tr>
<tr><td>Drag from one drawable element to another, and from outside the canvas into it</td><td>works</td><td>Selects across them in document order.</td></tr>
<tr><td>Drag from outside into a <code>contenteditable</code> canvas child</td><td>stops at its edge</td><td>The usual editing-boundary rule.</td></tr>
<tr><td>Caret of a focused editable canvas child</td><td>works</td><td>Drawn, and each blink fires <code>paint</code> (4 events in 2.2 s).</td></tr>
<tr><td>Selection inside <code>&lt;input&gt;</code> or <code>&lt;textarea&gt;</code></td><td>drawn, cannot be measured</td><td><code>getSelection()</code> has no range inside the control and there is no rectangle API for <code>selectionStart</code>/<code>selectionEnd</code>.</td></tr>
<tr><td><code>window.find()</code></td><td>works</td><td>It selects the match, so it is drawn like any selection.</td></tr>
<tr><td>WebGPU against WebGL for the same effect (off-screen, software adapter)</td><td>works</td><td>Mean difference 0.00 of 255 for <code>wave</code>. The WGSL of all three shader effects compiles.</td></tr>
<tr><td>Touch long press, Android handles, the copy menu</td><td>not verified</td><td>Long press selected nothing in the headless browser, inside or outside a canvas. Needs a phone, in particular: handles on a rotated line, and handles when <code>::selection</code> is transparent.</td></tr>
<tr><td><code>::target-text</code>, find-in-page marks, spelling marks</td><td>not verified</td><td>None appeared in the headless browser even outside a canvas. The explainer lists spelling and find-in-page marks as left out of element pictures.</td></tr>
<tr><td><code>WEBGL_lose_context.loseContext()</code> on an attached drawable WebGL canvas that holds an element texture</td><td>crashes the tab (Chromium 157)</td><td>Seen in a live check that released its context while the fixture was still in the document. Removing the canvas first avoids it.</td></tr>
<tr><td>A WebGL canvas losing its context</td><td>fires <code>webglcontextlost</code>, not <code>contextlost</code></td><td><code>SurfaceElement</code> in <code>lib/surface.js</code> only listens for <code>contextlost</code>, so a subclass using WebGL has to listen itself. <code>&lt;selection-fx&gt;</code> moves its content to a new 2D canvas on either event.</td></tr>
<tr><td>A canvas with a lost context on Android Chrome 159</td><td>shows a white box with a broken-picture icon</td><td>Reported from Paul's phone on first load of <code>/selection/</code> (2026-11-21), cause not identified. The page now starts on a 2D effect, starts GPU checks only on a tap, and replaces a lost or picture-less canvas.</td></tr>
<tr><td><code>caret-color</code> and <code>caret-shape</code> in the element's picture (<code>/caret/</code>)</td><td>works</td><td>At device scale factor 2 a block caret covers 578 canvas pixels and a bar 102.</td></tr>
<tr><td><code>caret-animation: manual</code></td><td>works</td><td>The caret pixels stay in every read-back and no <code>paint</code> fires while the caret rests. With <code>auto</code> the caret is in about one read-back in three.</td></tr>
<tr><td>Caret position from a collapsed <code>Range</code></td><td>works</td><td><code>getClientRects()</code> returns one zero-width rectangle at the drawn position. Nothing on an empty line.</td></tr>
<tr><td><code>CSS.highlights.highlightsFromPoint()</code> on an element drawn away from its layout position</td><td>works</td><td>Returns the Highlight and range at the drawn position, and nothing at an empty point of the canvas.</td></tr>
<tr><td><code>::highlight(*)</code></td><td>not in Chromium 157</td><td><code>CSS.supports('selector(::highlight(*))')</code> is false. Listed for 158.</td></tr>
<tr><td>A shader finding the caret and highlights by colour key, with no rectangles (<code>key-glow</code>)</td><td>works</td><td>Checked on WebGL with a keyed <code>::highlight()</code> background.</td></tr>
<tr><td>Playwright screenshots</td><td>hide the caret</td><td><code>page.screenshot()</code> defaults to <code>caret: 'hide'</code>. Pass <code>caret: 'initial'</code> when the caret is the subject.</td></tr>
<tr><td>WebGPU on screen, and shader speed on a phone</td><td>not verified</td><td>The software adapter cannot present a WebGPU canvas.</td></tr></tbody></table>
<p>How <code>&lt;selection-fx&gt;</code> uses this: one <code>::selection</code> rule hides the browser's highlight inside the element, <code>selectionchange</code> triggers a measurement of one Range per text node, and the rectangles go to a 2D effect directly or to a shader as a mask texture (red: selected, green: selected in the last 1.2 s, blue: selected and blurred by 10 px). The element's geometry stays at its layout position, so the caret and hit testing do not follow what an effect draws.</p>
<p><a href="https://html-in-canvas.page/selection/">Open Text selection effects</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>CSS shapes lit as solids</title>
<link>https://html-in-canvas.page/shape-ui/</link>
<guid isPermaLink="true">https://html-in-canvas.page/shape-ui/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>corner-shape</category>
<category>shape()</category>
<category>border-shape</category>
<category>deviceorientation</category>
<description>Buttons with corner-shape, border-shape and clip-path: shape() outlines, lit by a shader that reads the picture's alpha as height. Bevels and shadows follow each outline, and the light follows the pointer or the phone's tilt.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/shape-ui/"><img src="https://html-in-canvas.page/shape-ui/social.jpg" width="1200" height="630" alt="The page &quot;CSS shapes lit as solids&quot;"></a></p>
<p><strong>Question:</strong> Are the new CSS outlines (<code>corner-shape</code>, <code>border-shape</code>, <code>shape()</code>) in the alpha channel of a drawn element, and is that enough for a shader to light the element as a solid?</p>
<p><strong>Short answer:</strong> Yes. Sixteen alpha samples per pixel give a usable normal, and the shadow gets the right outline. Hit testing follows all three outlines.</p>
<p>
The pieces below are buttons and boxes whose outlines come from <code>corner-shape</code>, <code>border-shape</code> and
<code>clip-path: shape()</code>. A fragment shader treats each picture's alpha channel as the height of a solid and lights it: the edges
are bevelled, and each piece casts a shadow with its own outline. Move the pointer or drag a finger across the panel to move the light.
Press the pieces.
</p>
<h3>How it works</h3>
<ul>
<li>The <a href="https://html-in-canvas.page/shader-css/">fx library</a> moves each piece into a canvas and gives the shader the piece's picture as a texture with premultiplied alpha. Whatever CSS does to the outline is already in the alpha channel.</li>
<li>For each pixel the shader reads alpha at 16 points in a disc of 7 px. The share of points inside the shape is the height: 1 well inside, about 0.5 on the edge. The average of the points' offsets, weighted by alpha, points away from the nearest edge. That gives a normal without a second pass.</li>
<li>Labels are embossed with a second, smaller slope taken from the brightness of the picture.</li>
<li>The shadow is the same alpha read 16 px towards the light, through 8 jittered samples.</li>
<li>The seven keys of the keypad are one picture. A pressed key is scaled to 0.9 by <code>:active</code>, which changes the alpha, and the lighting follows with no code for it.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: every outline is in the alpha channel.</strong> <code>corner-shape</code> (squircle, bevel, scoop, notch, superellipse), <code>border-shape: circle()</code> and <code>clip-path: shape()</code> all change the picture the shader receives, so one shader lights all of them.</li>
<li><strong>Works: normals from 16 samples.</strong> The bevel is smooth at 7 px. Below about 3 px the samples land less than a pixel apart and the bevel becomes a plain edge highlight. Above about 14 px the 16 samples show as faint steps.</li>
<li><strong>Hit testing follows all three outlines.</strong> A point in a corner that <code>corner-shape</code>, <code>border-shape</code> or <code>clip-path</code> cut away is outside the element for <code>elementFromPoint()</code>, in a canvas and as plain DOM. A click in the gap between a piece's box and its outline doesn't press it. The shader moves no pixels, so no geometry update is needed.</li>
<li><strong>Limit: the shader can't see behind a piece.</strong> A shadow is drawn in the canvas of the piece that casts it, inside 30 px of extra canvas round the piece. It doesn't darken a neighbour that is itself a canvas above it.</li>
<li><strong>Not verified here:</strong> the tilt sensor (the test browser has none), and the frame rate on a phone, where each piece costs 29 texture reads per pixel while the light moves.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/effects-from-css.md">findings/effects-from-css.md</a> in the repository.</p>
<h3><code>/scroll-fx/</code> and <code>/shape-ui/</code></h3>
<p>Built from the Chrome APIs plan (<code>/chrome-apis/</code>, demos 6 and 7). Both pages use the <code>fx</code> attribute, with effects defined in the page. Chromium 157, software rendering.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>animation-timeline: view()</code> on an element that is a canvas child, animating <code>--fx-progress</code></td><td>works</td><td>The element's view timeline follows the page's scroll position although the element is only drawn through its canvas. The fx library reads the property once per frame.</td></tr>
<tr><td><code>animation-timeline: scroll(root)</code> on an ancestor, inherited by canvas children</td><td>works</td><td>Registered custom properties with <code>inherits: true</code> cross the shadow root and the canvas.</td></tr>
<tr><td>Scroll speed with no script: <code>--lag: var(--pos); transition: --lag 120ms linear</code>, speed = <code>--pos - --lag</code></td><td>works</td><td>The transition has to be on a descendant of the element whose animation moves <code>--pos</code>. Peak difference 0.42 of the scroll range in the check.</td></tr>
<tr><td><code>scroll-state(stuck: top)</code> container outside the canvas styling an element inside it</td><td>works</td><td>The sticky holder is the query container. The drawn bar gets <code>--fx-amount: 1</code> and a new background.</td></tr>
<tr><td><code>timeline-trigger</code> with <code>animation-trigger: play-forwards reset</code> on a canvas child</td><td>works</td><td>The animation runs by the clock after the scroll stops. In the small check fixture the reset on leaving was not seen within 200 ms. On the page it resets.</td></tr>
<tr><td>A drawer on the overscroll area</td><td>not built</td><td>No <code>overscroll-area</code> property in Chromium 157.</td></tr>
<tr><td><code>corner-shape</code>, <code>border-shape: circle()</code>, <code>clip-path: shape()</code> in the element's alpha</td><td>works</td><td>Corner pixel alpha 0, middle 255, for all three.</td></tr>
<tr><td>A normal from alpha: 16 samples in a 7 px disc, height = share inside, slope = alpha-weighted mean offset</td><td>works</td><td>One pass, no blur pass. Smooth between about 3 px and 14 px of bevel.</td></tr>
<tr><td>A shadow with the element's outline, drawn by the element's own shader</td><td>works</td><td>Alpha read 18 px towards the light, 8 jittered samples, inside 30 px of canvas bleed. It cannot darken a neighbouring canvas.</td></tr>
<tr><td><code>elementFromPoint()</code> in a corner cut away by <code>corner-shape</code>, <code>border-shape</code> or <code>clip-path</code></td><td>outline</td><td>Not the element, in a canvas and as plain DOM. Hit testing follows all three outlines.</td></tr>
<tr><td>Pressing: <code>:active</code> scales a key inside a shared picture</td><td>works</td><td>The alpha changes, so bevel and shadow follow with no code.</td></tr>
<tr><td>GLSL and WGSL versions of the eight new effects give the same picture</td><td>works</td><td>Mean difference under 0.4 of 255 per channel, WebGPU drawn into a texture on a software adapter.</td></tr></tbody></table>
<p>Both pages ask <code>/shared/backend.js</code> for WebGPU first and otherwise mark every element <code>fx-backend="shared"</code>, so a page opens one WebGPU device or one WebGL context (<code>/shared/fx-route.js</code>).</p>
<p><a href="https://html-in-canvas.page/shape-ui/">Open CSS shapes lit as solids</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A share card from a selection</title>
<link>https://html-in-canvas.page/share-card/</link>
<guid isPermaLink="true">https://html-in-canvas.page/share-card/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>canvas.toBlob()</category>
<category>navigator.share()</category>
<description>Select a passage and a canvas draws it as a share card: an HTML figure styled with CSS, drawn at 1200 × 630, 1080 × 1080 or 1080 × 1920 and saved, shared or copied as a PNG.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/share-card/"><img src="https://html-in-canvas.page/share-card/social.jpg" width="1200" height="630" alt="The page &quot;A share card from a selection&quot;"></a></p>
<p><strong>Question:</strong> Can a card laid out by CSS be exported as a picture at a larger size than its layout, with the emphasis of the selected text kept?</p>
<p><strong>Short answer:</strong> Yes. The element is drawn again at the target size and the canvas isn't tainted.</p>
<p>
Select a passage in the article. The card under it shows the passage, with its emphasis, in the largest type that fits. The card is an HTML figure styled with CSS and drawn by a canvas, so it can be saved, shared or copied as a PNG.
</p>
<h3>How it works</h3>
<p>
The figure is a <code>drawable</code> child of a canvas with <code>layoutsubtree</code>, so the browser lays it out and styles it like any element, and <code>scrollHeight</code> on it reports whether the quote fits. The figure is 600 by 315 CSS pixels for the link preview size. The canvas bitmap is 1200 by 630, and <code>drawElementImage(figure, 0, 0, 1200, 630)</code> draws the figure at twice its layout size. <code>canvas.toBlob()</code> gives the PNG. The selected text is copied with <code>Range.cloneContents()</code>, keeping <code>em</code>, <code>strong</code> and <code>code</code> and flattening everything else.
</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.</p>
<ul>
<li><strong>A figure drawn larger than its layout is drawn again, not stretched.</strong> The check below draws a 1 px line at four times its size and finds hard edges. A card laid out at 600 px therefore exports at 1200 px with sharp type.</li>
<li><strong>The canvas isn't tainted</strong> by same-origin element content: <code>toBlob()</code> returns a PNG of the requested size for all three formats.</li>
<li><strong>Layout queries work on a canvas child.</strong> <code>scrollHeight</code> and <code>clientHeight</code> of the figure drive the type size, with no canvas text measuring.</li>
<li><strong>The figure's layout box can be larger than the canvas element.</strong> The canvas is shown at the width of the page (about 396 px on a phone) while the figure is 600 px wide. The picture is complete, and the page doesn't scroll sideways because the stage clips.</li>
<li><strong>The figure is <code>inert</code>.</strong> It is drawn at a different size from its layout, so its hit boxes would be in the wrong place. Nothing in it needs to be pressed.</li>
</ul>
<p><strong>Not verified:</strong> <code>navigator.share()</code> with a file and writing a PNG to the clipboard (the headless browser has neither a share sheet nor clipboard permission), and how the saved picture looks in a messaging app.</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/selection.md">findings/selection.md</a> in the repository.</p>
<h3>Five pages drawn from ranges (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>, <code>/redact/</code>, <code>/selection-heat/</code>, <code>/share-card/</code>)</h3>
<p>Measured in headless Chromium 157 (Linux, software renderer, device scale factor 2) on 2026-11-21. Each row is a live check on the page named. The first four pages are 2D effects registered on <code>&lt;selection-fx&gt;</code> with <code>defineSelectionEffect()</code> from their own modules. Shared helpers are in <code>lib/selection-tools.js</code> and shared styles in <code>lib/selection-article.css</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Rectangles of a range that is not selected (<code>/selection-peers/</code>)</td><td>works</td><td><code>Range.getClientRects()</code> needs no selection. A canvas draws any number of other readers' ranges with no change to the DOM or to the document's selection (HTML and selection compared before and after).</td></tr>
<tr><td>A selection sent as two offsets into <code>textContent</code> and rebuilt in another document</td><td>works</td><td>Round trip checked across an inline element. A message on a <code>BroadcastChannel</code> arrived in 25 ms and the range was drawn 48.2 px wide for 4 characters of 12 px.</td></tr>
<tr><td>A same-origin frame as a second reader</td><td>works</td><td>Each document has its own selection, so selecting in the frame does not clear the page's selection. Checked with a script, not a live check: both selections were held at once and each side drew the other's range.</td></tr>
<tr><td>One <code>Range</code> per character (<code>/selection-glyphs/</code>)</td><td>works</td><td>12 rectangles for 12 letters, each 12.0 px wide in a 20 px monospace font. The box is the advance width and the line's text height, not the ink.</td></tr>
<tr><td>Letters taken out of the element's picture with an even-odd clip and drawn elsewhere</td><td>works</td><td>After dropping 12 letters: 0 ink pixels on their line, 3047 under it, <code>textContent</code> unchanged.</td></tr>
<tr><td>The canvas outside the element's ink</td><td>transparent</td><td>An element with no background leaves the canvas transparent between glyphs, so a piece of the canvas is a letter with nothing behind it.</td></tr>
<tr><td>288 letters per frame from a snapshot (<code>drawImage()</code>) against from the live element (<code>drawElementImage()</code> through a clip, once per letter)</td><td>49.6 ms against 442.3 ms</td><td>Software renderer, and both numbers include <code>getImageData()</code> of the whole canvas. The live route replays the element's paint record once per letter.</td></tr>
<tr><td>A bar drawn over a range after the element (<code>/redact/</code>)</td><td>covers every pixel</td><td>10560 canvas pixels inside the range's rectangle, all the bar colour.</td></tr>
<tr><td>The DOM after a canvas redaction</td><td>still has the text</td><td><code>textContent</code>, <code>Range.toString()</code> and copy return it. The page's copy handler and "Remove the text from the DOM" are the two ways it offers to close that.</td></tr>
<tr><td><code>ctx.filter = 'blur()'</code> on <code>drawElementImage()</code></td><td>works</td><td>The blur style changed 9196 pixels inside the range and 0 outside. Filter lengths are canvas pixels, so the page multiplies by the canvas scale.</td></tr>
<tr><td><code>drawImage(canvas)</code> with the canvas itself as the source, after <code>drawElementImage()</code></td><td>works</td><td>The pixel style reads the part of the canvas it replaces. The canvas is not tainted by same-origin element content.</td></tr>
<tr><td>Replacing characters in the DOM under a Custom Highlight range</td><td>offsets stay valid</td><td>Setting <code>node.data</code> collapses live ranges in that node, so the page rebuilds its ranges from stored offsets. 10 characters replaced, the range kept one rectangle.</td></tr>
<tr><td>One element drawn twice in a frame at different sizes (<code>/selection-heat/</code>)</td><td>works</td><td>The minimap is the article at scale 0.169 in the fixture: 478 text pixels and 57 heat pixels at the scaled position.</td></tr>
<tr><td>A minimap in a second canvas</td><td>not possible</td><td>An element is drawn only by its own canvas (known from the first findings), so the minimap is inside the article's canvas, in a column the article reserves with padding.</td></tr>
<tr><td><code>document.caretPositionFromPoint()</code> on text drawn by the canvas</td><td>works</td><td>Returned offset 7 for a point on the eighth character.</td></tr>
<tr><td>An element drawn at four times its layout size (<code>/share-card/</code>)</td><td>drawn again, not stretched</td><td>A 1 px line became 4 black pixels with 0 grey pixels beside it.</td></tr>
<tr><td><code>canvas.toBlob()</code> after <code>drawElementImage()</code></td><td>works</td><td>PNGs of 1200×630, 1080×1080 and 1080×1920 decoded at those sizes.</td></tr>
<tr><td><code>scrollHeight</code> and <code>clientHeight</code> on a canvas child</td><td>work</td><td>They drive the card's type size: 67.5 px for 3 words, smaller for 420 characters, both fit.</td></tr>
<tr><td>A canvas child wider than the canvas element</td><td>works</td><td>The figure is 600 px wide in a canvas shown about 396 px wide. The picture is complete.</td></tr></tbody></table>
<h4>Things that bit</h4>
<ul><li><code>shared/style.css</code> gives <code>figure</code> a <code>max-width: 100%</code>, and a canvas child obeys it against the canvas's CSS width. The share card was laid out 396 px wide and drawn stretched until the figure got <code>max-width: none</code>.</li>
<li>After a 2D <code>drawElementImage()</code> with a size different from the layout size, <code>getBoundingClientRect()</code> of the element reports the drawn size (396×208 for a 600×315 figure). Layout sizes come from <code>offsetWidth</code> and <code>clientHeight</code>.</li>
<li><code>s.rects</code> in a <code>&lt;selection-fx&gt;</code> effect holds the selection and the <code>highlight</code> attribute's ranges together. An effect that draws the two differently reads <code>s.marked</code> for the ranges and uses <code>s.rects</code> only while something is selected.</li>
<li>Fitting type by <code>scrollHeight</code> and then changing <code>line-height</code> undoes the fit. The line height is fixed in CSS.</li>
<li>Reported from Paul's phone (Android Chrome 159) through the coordinator on 2026-11-21, not measured here: a drawable 2D canvas that is read back with <code>getImageData()</code> (with <code>willReadFrequently</code>) lost every 2D context on the page. These five pages never call <code>getImageData()</code> on a drawable canvas. <code>snapshot()</code> and <code>copyCanvas()</code> in <code>lib/selection-tools.js</code> copy the canvas to an <code>OffscreenCanvas</code> with <code>drawImage()</code> and read the copy.</li>
<li>The site menu stays at the top of the window, so a minimap that follows the scroll is placed 64 px below the window's top edge.</li>
<li>The article's own minimap column is part of the element, so the minimap shows an empty strip at its right edge.</li></ul>
<h4>Not verified</h4>
<ul><li>Touch on all five pages: long-press selection, the Android handles, the automatic drop 0.7 s after the last selection change on <code>/selection-glyphs/</code>, and dragging in the minimap column on <code>/selection-heat/</code>. Needs a phone.</li>
<li>Frame rate with several hundred loose letters, and how closely the minimap follows a touch scroll. Needs a phone.</li>
<li><code>navigator.share()</code> with a PNG file and <code>navigator.clipboard.write()</code> with a PNG on <code>/share-card/</code>. The headless browser has no share sheet and no clipboard permission. Press Share and Copy picture on a phone.</li>
<li>What find-in-page and TalkBack report for a range covered on <code>/redact/</code>. Both read the DOM, so the expected answer is the original text until it is removed.</li>
<li>Two people on two devices on <code>/selection-peers/</code>. The page has a <code>BroadcastChannel</code> only, so it reaches tabs and frames of one browser. A relay server would carry the same message.</li></ul>
<h4>Ideas not built</h4>
<ul><li>A relay (Durable Object or WebRTC data channel) so <code>/selection-peers/</code> works between devices, and readers' carets as well as selections.</li>
<li>Letters on <code>/selection-glyphs/</code> that collide with each other and can be pushed with a finger.</li>
<li>Redaction that also exports a PDF, and a "peek" that shows a range while it is pressed.</li>
<li>Heat collected from real visitors, and a minimap for a whole page of several canvases.</li>
<li>Share cards with a QR code of a text-fragment link to the passage.</li></ul>
<h4>For the index</h4>
<ul><li>Text and ranges: any <code>Range</code> has rectangles at the drawn position whether or not it is selected; one <code>Range</code> per character gives per-letter boxes (<code>/selection-peers/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: <code>ctx.filter</code>, <code>clip('evenodd')</code> and a self-sourced <code>drawImage()</code> all apply to <code>drawElementImage()</code> output (<code>/redact/</code>, <code>/selection-glyphs/</code>).</li>
<li>2D drawing: an element drawn larger than its layout is re-rasterised, and one element can be drawn several times per frame at different sizes (<code>/share-card/</code>, <code>/selection-heat/</code>).</li>
<li>Export: <code>toBlob()</code> and <code>getImageData()</code> work after <code>drawElementImage()</code> of same-origin content (<code>/share-card/</code>, <code>/redact/</code>).</li>
<li>Layout: <code>scrollHeight</code> works on canvas children; <code>max-width: 100%</code> on a canvas child resolves against the canvas's CSS width (<code>/share-card/</code>).</li>
<li>Accessibility and privacy: drawing over text in the canvas hides nothing from the DOM (<code>/redact/</code>).</li></ul>
<p><a href="https://html-in-canvas.page/share-card/">Open A share card from a selection</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Sortable table: rows travel to their new places</title>
<link>https://html-in-canvas.page/sort-table/</link>
<guid isPermaLink="true">https://html-in-canvas.page/sort-table/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>tr drawable</category>
<category>drawElementImage</category>
<category>captureElementImage</category>
<category>moveBefore</category>
<description>A table with drawable on every row. A sort moves the rows in the DOM at once and the canvas draws each one flying from its old place to its new one, with its inputs live on the way.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/sort-table/"><img src="https://html-in-canvas.page/sort-table/social.jpg" width="1200" height="630" alt="The page &quot;Sortable table: rows travel to their new places&quot;"></a></p>
<p><strong>Question:</strong> Can each row of a real table be drawn on its own, so that a sort is shown as rows travelling while the table, its inputs and its sort buttons stay ordinary HTML?</p>
<p><strong>Short answer:</strong> Yes. A <code>&lt;tr drawable&gt;</code> keeps its table layout, can be drawn in the same task as the DOM move, and takes input at the drawn position.</p>
<p>
A table of files inside a canvas. Every <code>&lt;tr&gt;</code> has the <code>drawable</code> attribute, so the canvas draws each row on its own.
Tap a column heading to sort. The rows are reordered in the DOM at once, and the canvas draws each row moving from where it was to where it now belongs.
The number fields and checkboxes work while the rows move. Change a size or tick a box and sort again.
</p>
<h3>How it works</h3>
<p>The table is a child of the canvas and is laid out as a table. It has no <code>drawable</code> attribute, so it has no picture of its own. Each <code>&lt;tr drawable&gt;</code> has one.
On every <code>paint</code> event the canvas draws the heading row and the eight body rows with <code>drawElementImage()</code>, and each draw puts the row's hit region where the row was drawn.</p>
<p>A sort does three things in one task. It records the y position at which each row was last drawn. It calls <code>captureElementImage()</code> on each row to keep a picture of the row as it looked.
Then it moves the rows with <code>moveBefore()</code> (or <code>insertBefore()</code>). The table's layout changes at once: <code>offsetTop</code> of every row is its new place.
For the next 700 ms the canvas draws each row at a position between the recorded one and the new one. In "Arc and lift" a row that moves up swings out to the right, a row that moves down swings to the left, and both are scaled up with a shadow under them.
The trail is the same row drawn three more times at earlier points on its path with low alpha.</p>
<p>The striping comes from <code>:nth-child(even)</code>, so a row changes background the moment it is moved. With "Fade from the old look" on, the snapshot taken before the move is drawn over the live row and fades out during the travel.</p>
<p>The row is drawn last at its travel position, so taps and typing go to the moving row. With <code>moveBefore()</code> a number field that has focus keeps it through the sort.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 a <code>&lt;tr drawable&gt;</code> inside a table that is a canvas child keeps <code>display: table-row</code> and the column widths of its table, and can be drawn at any position. A <code>&lt;tr&gt;</code> that is the canvas's direct child is laid out as a block (recorded on <a href="https://html-in-canvas.page/elements/">/elements/</a>).</li>
<li>A row moved with <code>moveBefore()</code>, <code>insertBefore()</code> or <code>append()</code> can be drawn in the same task, before the next <code>paint</code> event. The picture is the one from before the move, so a style that depends on position, such as <code>:nth-child()</code> striping, shows one frame late.</li>
<li><code>captureElementImage(row)</code> taken before the move still draws after it. That gives the two pictures a cross-fade needs.</li>
<li>Inputs in a row that is drawn rotated, scaled and away from its layout position take taps at the drawn position.</li>
<li>A canvas shadow (<code>shadowBlur</code>) applies to <code>drawElementImage()</code> of a row.</li>
<li>With <code>insertBefore()</code> a focused number field loses focus when its row moves. With <code>moveBefore()</code> it keeps it (measured on <a href="https://html-in-canvas.page/patch/">/patch/</a>; the menu above switches between the two).</li>
<li>Not verified: frame rate of the travel on a phone, and the on-screen keyboard staying open through a sort.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/sort-table.md">findings/sort-table.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, 412 px wide, touch emulation) on 2026-11-21. Not yet run on A159.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>&lt;tr drawable&gt;</code> inside a <code>&lt;table&gt;</code> that is a canvas child</td><td>works</td><td>The row keeps <code>display: table-row</code> and the column widths of its table. The table has no <code>drawable</code> and no picture. <code>offsetTop</code> of a row is relative to the table.</td></tr>
<tr><td>Draw a row away from its layout position, rotated and scaled</td><td>works</td><td>Inputs in the row are hit at the drawn position (<code>elementFromPoint()</code> and real taps).</td></tr>
<tr><td>Move rows with <code>moveBefore()</code>, <code>insertBefore()</code> or <code>append()</code> and draw them in the same task</td><td>works</td><td>No <code>paint</code> event is needed between the move and the draw. <code>offsetTop</code> is already the new place. The picture is the one from before the move.</td></tr>
<tr><td><code>:nth-child()</code> striping on moved rows</td><td>one frame late</td><td>The first draw after the move uses the old picture. The next <code>paint</code> has the new background.</td></tr>
<tr><td><code>captureElementImage(row)</code> before the move, drawn after it</td><td>works</td><td>Used to fade from the old look of the row to the new one during the travel.</td></tr>
<tr><td><code>shadowBlur</code> and <code>shadowOffsetY</code> on <code>drawElementImage(row)</code></td><td>works</td><td>In an 8-bit 2D canvas. (<code>/hdr-glow/</code> records that this clamps in a float16 canvas.)</td></tr>
<tr><td>Draw one row four times in a frame (three trail copies with low alpha, then the row)</td><td>works</td><td>The hit region is that of the last draw.</td></tr>
<tr><td>A sort that starts while the rows are still travelling</td><td>works</td><td>The page remembers the y at which each row was last drawn and starts from there.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>table.offsetTop</code> is measured from the page, not from the canvas, because the canvas is not an offset parent. The first version drew every row 577 px too low and the canvas was blank. The table is at the canvas origin, so the page uses 0 and the rows' own <code>offsetTop</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>Frame rate of the travel on a phone. Opening <code>/sort-table/</code> on the phone and sorting would show it.</li>
<li>Whether the on-screen keyboard stays open when a focused number field's row is moved with <code>moveBefore()</code>.</li>
<li>Focus kept by <code>moveBefore()</code> and lost by <code>insertBefore()</code> was not measured here. <code>/patch/</code> measured it. The "Move with" menu on the page switches between the two.</li></ul>
<h3>Ideas built</h3>
<ul><li>"Sortable table with rows that travel" from <code>public/elements/ideas.js</code> (data).</li></ul>
<h3>Open ideas</h3>
<ul><li>Column reorder by dragging a heading, with each cell drawn on its own (<code>td drawable</code>) so a column can travel sideways.</li>
<li>Rows that leave and enter on filter, using the snapshot for the leaving row after it has been removed from the DOM.</li></ul>
<p><a href="https://html-in-canvas.page/sort-table/">Open Sortable table: rows travel to their new places</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Words highlighted as they are spoken</title>
<link>https://html-in-canvas.page/speak-words/</link>
<guid isPermaLink="true">https://html-in-canvas.page/speak-words/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>SpeechSynthesis</category>
<category>boundary</category>
<category>Range</category>
<category>drawElementImage</category>
<description>The browser reads a paragraph aloud with SpeechSynthesis. Each boundary event gives the position of a word, the page turns it into a Range rectangle, and the canvas draws a spotlight, a magnified copy or a sweep on that word. Tap a word to start from it. A voice that sends no boundary events is stepped by a timer.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/speak-words/"><img src="https://html-in-canvas.page/speak-words/social.jpg" width="1200" height="630" alt="The page &quot;Words highlighted as they are spoken&quot;"></a></p>
<p><strong>Question:</strong> Do SpeechSynthesis boundary events arrive well enough to draw an effect on each word as it is spoken, and can the paragraph still be tapped while a magnified copy of a word is drawn?</p>
<p><strong>Short answer:</strong> The drawing and the tap handling work from boundary events. Whether a voice sends them depends on the device: the page counts them and falls back to a timer.</p>
<p>
Press Speak and the browser reads the paragraph aloud. Each <code>boundary</code> event names the word being started, and the canvas draws an
effect on that word. Tap any word to start from it. If the voice sends no boundary events, the words are stepped by a timer and the line under
the buttons says so.
</p>
<h3>How it works</h3>
<ul>
<li><code>speechSynthesis.speak()</code> takes a <code>SpeechSynthesisUtterance</code>. While it speaks, the utterance fires <code>boundary</code> events with <code>charIndex</code>, and in newer engines <code>charLength</code> and the name <code>word</code> or <code>sentence</code>.</li>
<li>The page makes a <code>Range</code> from <code>charIndex</code> to the end of the word and reads <code>getClientRects()</code>. The rectangles are relative to the article, so the canvas can use them whatever size it draws the article at.</li>
<li>The canvas draws the article three times: once at 32% opacity, once clipped to the rectangles of the words already spoken, and once for the current word with the chosen effect. The spotlight's rectangle moves a fraction of the way to the new word on every frame.</li>
<li>The lens draws only the word's rectangle, 1.7 times larger. A draw call also moves the element's hit-test region, so after it the paragraph couldn't be tapped where it appears. The handler ends with one more full-size draw inside an empty clip, which draws nothing and restores the region.</li>
<li>The fourth effect draws nothing extra. Two CSS Custom Highlights are set on the same ranges and the browser paints them into the element's picture.</li>
<li>A tap calls <code>document.caretPositionFromPoint()</code>. The offset it returns is moved back to the start of the word, and a new utterance is spoken from there. Its <code>charIndex</code> values are then offsets from that point.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless, 2026-11-21, which has no voices. The rows above and the line under the buttons say what your browser does.</p>
<ul>
<li><strong>Works: a boundary event to a drawn word.</strong> With boundary events dispatched by hand, the range, its rectangle and the three canvas effects land on the right word.</li>
<li><strong>Works: <code>charLength</code> can be absent.</strong> The word's end is then found in the text from <code>charIndex</code>.</li>
<li><strong>Found: a partial draw moves the whole hit-test region.</strong> After the nine-argument draw of one word, <code>elementFromPoint()</code> at another word answered with the canvas, not the article. A final full-size draw inside an empty clip puts it back and adds no pixels.</li>
<li><strong>Works: <code>caretPositionFromPoint()</code> inside a drawn element.</strong> It returns the text node and the offset of the word under the point.</li>
<li><strong>Works: Custom Highlights are in the picture.</strong> A change to a <code>Highlight</code> is drawn after <code>requestPaint()</code>.</li>
<li><strong>Not run here: real speech.</strong> The test browser has no voices and <code>speak()</code> ends with the error <code>synthesis-failed</code>. The page then steps the words by a timer, which is the same path a voice without boundary events takes.</li>
<li><strong>Not verified:</strong> whether the voices of Chrome 159 on Android fire <code>boundary</code> events, whether they carry <code>charLength</code>, and how far the events lead or trail the sound. Press Speak and read the line under the buttons: it shows the count of events and the time to the <code>start</code> event. The last live check does the same with three words.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/speak-words.md">findings/speak-words.md</a> in the repository.</p>
<p>Chromium 157 headless (C157), 2026-11-21. The test browser has no voices: <code>speechSynthesis.getVoices()</code> is empty and <code>speak()</code> ends with the error <code>synthesis-failed</code>. Boundary events were therefore dispatched by hand (<code>new SpeechSynthesisEvent('boundary', …)</code> on the utterance) for every measured row. Real speech is not verified.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>boundary</code> event to a word</td><td>works</td><td><code>charIndex</code> and <code>charLength</code> give the range. Without <code>charLength</code> the end of the word is read from the text. Events named <code>sentence</code> are counted and not drawn.</td></tr>
<tr><td>Word to rectangle</td><td>works</td><td>A <code>Range</code> over the word, <code>getClientRects()</code>, made relative to the article and divided by the drawn scale.</td></tr>
<tr><td>Spotlight on the word</td><td>works</td><td>315 highlight pixels on the word, 0 on another word. The rectangle moves 35% of the way to the new word per frame and jumps when the line changes.</td></tr>
<tr><td>Spoken words at full ink, later words faint</td><td>works</td><td>The article is drawn at 32% opacity, then again through a clip made of the rectangles of the spoken range. Darkest red value 29 in a spoken word, 182 in a later one.</td></tr>
<tr><td>Magnified copy of the word (nine-argument <code>drawElementImage()</code>)</td><td>works</td><td>Source rectangle is the word, destination is 1.7 times larger.</td></tr>
<tr><td>Hit testing after that partial draw</td><td>wrong without a fix, right with it</td><td>After the nine-argument call, <code>elementFromPoint()</code> at another word returned the canvas: the call maps the whole element's hit box through the word's source-to-destination mapping. One more full-size <code>drawElementImage()</code> inside an empty clip (<code>rect(0, 0, 0, 0)</code>) draws no pixels and puts the hit box back.</td></tr>
<tr><td><code>document.caretPositionFromPoint()</code> on a drawn paragraph</td><td>works</td><td>Returned the text node and offset 31, inside "seven". A tap on a word starts a new utterance from that word.</td></tr>
<tr><td>CSS Custom Highlights on the same ranges</td><td>in the element's picture</td><td><code>::highlight(spoken-word)</code> gave 501 highlight pixels with one draw call and no other canvas work.</td></tr>
<tr><td>No boundary events</td><td>stepped by a timer</td><td>If no boundary event arrives within 0.7 s of <code>start</code>, or the utterance fails, words are stepped from an estimate (0.17 s plus 0.052 s per letter, divided by the rate). The page says which source is in use.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A <code>filter: invert(1)</code> set on the context for the sweep effect produced a blue block. The sweep now fills a band and draws the text over it.</li>
<li>The first version of the timer check ran at rate 8, where every word falls before the 0.7 s wait and nothing was stepped.</li>
<li>The article's height sets the canvas's height. It is read once on load and again from a <code>ResizeObserver</code>, and assigned only when it changed.</li></ul>
<h3>Not verified</h3>
<ul><li>Whether the voices of Chrome 159 on Android fire <code>boundary</code> events at all, whether they carry <code>charLength</code>, and how far the events lead or trail the sound. Press Speak on the phone: the line under the buttons shows the time to <code>start</code>, the number of boundary events and the number with <code>charLength</code>. The last live check does the same with three words at zero volume.</li>
<li>Whether an utterance at zero volume still fires boundary events.</li>
<li>Long texts. Desktop Chrome has stopped network voices after about 15 s in the past (reported, not measured here).</li></ul>
<h3>Open ideas</h3>
<ul><li>The same reader over <code>&lt;selection-fx highlight="spoken-word"&gt;</code>, to use its shader effects.</li>
<li>Speech marks (<code>&lt;mark&gt;</code> in SSML) as triggers for effects on other elements.</li></ul>
<p><a href="https://html-in-canvas.page/speak-words/">Open Words highlighted as they are spoken</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Split-flap output element</title>
<link>https://html-in-canvas.page/split-flap/</link>
<guid isPermaLink="true">https://html-in-canvas.page/split-flap/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>output</category>
<category>captureElementImage</category>
<category>drawElementImage source rect</category>
<category>paint</category>
<description>A departure board of six &lt;output&gt; elements. A form sets their values and the canvas flips each changed character, through the alphabet or straight from a snapshot of the old picture to the new one.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/split-flap/"><img src="https://html-in-canvas.page/split-flap/social.jpg" width="1200" height="630" alt="The page &quot;Split-flap output element&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas turn a change of <code>output.value</code> into a split-flap flip for each character, using only the <code>paint</code> event to learn about the change?</p>
<p><strong>Short answer:</strong> Yes. Setting the value fires <code>paint</code>. The nine-argument <code>drawElementImage()</code> draws single characters from a hidden drum element or from a snapshot of the old board.</p>
<p>
A departure board made of six <code>&lt;output&gt;</code> elements, drawn by a canvas. The form under the canvas sets their values. When a value changes, the canvas flips each character that differs
to its new one, card by card. Type a message, move the delay slider or press Next departure. The Flip menu switches between stepping through the alphabet and turning straight from the old picture to the new one.
</p>
<h3>How it works</h3>
<p>Setting <code>output.value</code> changes the element's text, and the browser fires <code>paint</code> on the canvas. The paint handler reads the value of each output and compares it, character by character,
with what its flaps show. That comparison is the only link between the form and the board. The canvas code has no input listener and no observer.</p>
<p>Each character has a box, measured with a <code>Range</code>. The canvas draws a card behind every box, then the section itself, so a settled character is the browser's own text and can be selected.
A flap in motion is drawn from pieces of elements with the nine-argument form of <code>drawElementImage()</code>, which copies a source rectangle of an element's picture to a destination rectangle.</p>
<p>In the first mode a flap steps through the characters of a drum: a line of text in the same font that holds every character a flap can show. The drum is a second <code>drawable</code> child of the canvas. It's never drawn whole:
its characters are drawn one at a time. There's one drum for each style of output, so the yellow row flips in yellow. In the second mode the old face of a flap is a piece of a snapshot taken
with <code>captureElementImage()</code> before the change, and the new face is a piece of the live section. That mode needs no drum and works for any character.</p>
<h3>Findings</h3>
<ul>
<li>Setting <code>output.value</code> fires <code>paint</code> with no call from the page. A paint handler can treat the event as "something changed" and read the values itself.</li>
<li><code>drawElementImage(source, sx, sy, sw, sh, dx, dy, dw, dh)</code> works for an element and for an <code>ElementImage</code> snapshot. The source rectangle is in CSS pixels of the element.</li>
<li>A snapshot from <code>captureElementImage()</code> keeps the old value after the output changes, so one element can be the old face and the new face of a flap. <code>captureElementImage()</code> also works outside a paint handler.</li>
<li>The drum is a direct child of the canvas for a reason. As a <code>drawable</code> element nested in the section, its picture held only the characters that were inside the window, and which ones changed with
the place the drum was last drawn. Flaps then showed blank cards for the rest. A direct child of the canvas is recorded whole. <a href="https://html-in-canvas.page/keycaps/">Keycaps drawn from kbd</a> has a live check for this.</li>
<li>An <code>&lt;output form="…"&gt;</code> inside the canvas is in <code>form.elements</code> of a form outside it.</li>
<li>With <code>letter-spacing</code>, the box of a character includes the space after it, and the glyph is at the left of the box. The cards are shifted left by half the spacing to centre the glyphs.</li>
<li>Not verified: Chrome 159 for Android, and whether a screen reader announces the new value once (an <code>&lt;output&gt;</code> is a live region). Turn on TalkBack, press Next departure and listen for one announcement per row.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/split-flap.md">findings/split-flap.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21, at 412 px wide with a device scale factor of 2 and at 1100 px wide. Not yet run on the test phone (Chrome 159 for Android).</p>
<p>Idea built: "Split-flap output" from <code>public/elements/ideas.js</code> (rank 2, forms).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Does setting <code>output.value</code> fire <code>paint</code>?</td><td>measured: yes</td><td>1 paint event, no <code>requestPaint()</code>. The paint handler compares each output's value with what its flaps show. The canvas code has no input listener and no observer.</td></tr>
<tr><td>Nine-argument <code>drawElementImage(source, sx, sy, sw, sh, dx, dy, dw, dh)</code> on an element</td><td>measured: works</td><td>The source rectangle is in CSS pixels of the element at any device scale factor. 390 pixels in the destination box, 0 outside it. Against a clipped full draw of the same box, 244 of 18048 channel values differed (edges).</td></tr>
<tr><td>The same call on an <code>ElementImage</code> from <code>captureElementImage()</code></td><td>measured: works</td><td></td></tr>
<tr><td>Does a snapshot keep the old value?</td><td>measured: yes</td><td>The first character's box drew 402 pixels from the snapshot (A) and 49 from the live element (a full stop).</td></tr>
<tr><td><code>captureElementImage()</code> outside a paint handler</td><td>measured: works</td><td>Used at the end of a settled paint here, and in a timer on <code>/flip-clock/</code>.</td></tr>
<tr><td>Is an <code>&lt;output form="id"&gt;</code> inside the canvas in <code>form.elements</code> of a form outside it?</td><td>measured: yes</td><td></td></tr>
<tr><td>A drum (a line of every flap character) as a drawable nested in the section</td><td>measured: characters outside the window have no picture</td><td>See <code>findings/keycaps.md</code>. The drums are direct children of the canvas.</td></tr>
<tr><td>Box of a character with <code>letter-spacing</code></td><td>measured: the spacing is inside the box, after the glyph</td><td>A 12 px glyph with 10 px spacing has a 22 px box with ink from 1 to 10.5 px. Cards are shifted left by half the spacing.</td></tr>
<tr><td>Does the page stop asking for frames when the flaps settle?</td><td>measured: yes</td><td>0 <code>requestAnimationFrame()</code> calls in the 300 ms after settling.</td></tr>
<tr><td>Does a point on a drawn character hit test to the output?</td><td>measured: yes</td><td>After the pieces are drawn, a whole draw inside an empty clip (<code>home()</code>) puts the hit region back. <code>updateElementGeometry()</code> alone leaves it the size of the last piece.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>An <code>ElementImage</code> has a <code>close()</code> method and holds memory until it is called. The first version took a new snapshot at every settled paint and closed none. The board now closes the old snapshot before it takes a new one. A closed snapshot throws <code>InvalidStateError</code> when drawn.</li></ul>
<ul><li>The live text shows the new value at once, so a card that is still flipping is drawn again over the section's picture.</li>
<li>A drum in the board's own colour made the yellow row flip in white. There is one drum per output style.</li>
<li>Fixed-pitch fonts differ in advance width, so the font size is set from a measured character box and not from an assumed 0.6 em.</li>
<li>A snapshot compare of "A" against "I" failed its threshold in a fixed-pitch font, because "I" has wide serifs there.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 for Android, including the speed of 120 cards with up to 120 flaps in motion.</li>
<li>Screen readers: an <code>&lt;output&gt;</code> is a live region. Whether TalkBack announces each new row once is not measurable here. To verify: turn TalkBack on and press Next departure.</li>
<li>Selection of a row by long press on the phone.</li></ul>
<h3>Open ideas</h3>
<ul><li>A flap sound from Web Audio, one click per flip, started by the first tap.</li>
<li>Flaps for any element: the direct mode works on pictures, so a table cell or a price could flip the same way.</li></ul>
<p><a href="https://html-in-canvas.page/split-flap/">Open Split-flap output element</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Streamed HTML drawn as it arrives</title>
<link>https://html-in-canvas.page/stream/</link>
<guid isPermaLink="true">https://html-in-canvas.page/stream/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>streamAppendHTML</category>
<category>paint</category>
<category>texElementSubImage2D</category>
<description>Markup is streamed into an element in a canvas with streamAppendHTML(). Each chunk raises a paint event, and a shader draws the newest blocks through a scan line, a blur or spreading ink.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/stream/"><img src="https://html-in-canvas.page/stream/social.jpg" width="1200" height="630" alt="The page &quot;Streamed HTML drawn as it arrives&quot;"></a></p>
<p><strong>Question:</strong> When markup is streamed into an element in a canvas, does the canvas get a paint event for each chunk, and can it draw the newest blocks differently from the rest?</p>
<p><strong>Short answer:</strong> In Chromium 157 each chunk raises one paint event with no call to requestPaint(). A MutationObserver gives the new blocks, and one shader pass draws them through an effect while the text stays selectable.</p>
<p>
Markup is written into an element in small chunks with <code>streamAppendHTML()</code>. The element is a child of a canvas, and each chunk raises the canvas's
<code>paint</code> event. A fragment shader draws every new block through an effect and makes the block that is being written glow. The text is DOM the whole time, so you can select it, scroll it and press the button when it arrives.
</p>
<h3>How it works</h3>
<p>The document is one <code>drawable</code> child of the canvas. A writer from <code>streamAppendHTML()</code> receives the chunks. A <code>MutationObserver</code> records when each top-level block appeared and last changed. On every <code>paint</code> event the element is uploaded as one texture with <code>texElementSubImage2D()</code> and drawn on one quad; the fragment shader gets the rectangles and ages of the newest blocks as uniforms and applies the effect inside them. The quad covers the element's layout box, so <code>updateElementGeometry()</code> gets an identity matrix.</p>
<h3>Findings</h3>
<ul>
<li><code>streamAppendHTML()</code> raises one <code>paint</code> event per chunk with no call to <code>requestPaint()</code> (Chromium 157). The page counts the events under the stage.</li>
<li>The <code>paint</code> event doesn't say which block is new: <code>changedElements</code> lists drawable children of the canvas, and the whole document is one child. A <code>MutationObserver</code> supplies the per-block timing.</li>
<li>The document scrolls inside its own box while it's drawn through the shader, and it keeps to the bottom while text arrives. Block rectangles are measured every frame, so the effect stays on its block during a scroll.</li>
<li>Chromium 153 has no <code>streamAppendHTML()</code>. Writing the chunks with <code>document.write()</code> into a second document, after moving that document's container into the canvas child, gives the same result there.</li>
<li>Not verified here: the on-device model. The test browser reports the Prompt API as downloadable and can't download it, so the model button has only been run against a stub.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/stream.md">findings/stream.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell). Not yet run on the test phone.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>streamAppendHTML()</code> into a drawable canvas child</td><td>works</td><td>The writer accepts chunks that split a tag. Where the method is missing the page streams through <code>document.write()</code> on a second document whose container is moved into the page.</td></tr>
<tr><td>Paint event per chunk</td><td>yes</td><td>One <code>paint</code> event for each chunk that changed the picture, with no call to <code>requestPaint()</code>.</td></tr>
<tr><td>Which blocks are new</td><td>from a MutationObserver</td><td><code>changedElements</code> names the drawable element, not the blocks inside it. The page records the time each block was added or last changed and passes up to 16 rectangles to the shader.</td></tr>
<tr><td>Effect on new blocks only</td><td>works</td><td>One fragment shader pass over the element's texture. Older blocks are drawn unchanged.</td></tr>
<tr><td>Selection, links and buttons during the effect</td><td>work</td><td>The quad covers the element's layout box, so <code>updateElementGeometry()</code> with an identity matrix is enough. Without that call a WebGL canvas has no hit box for the child and <code>elementFromPoint()</code> returns the canvas.</td></tr>
<tr><td>Lost WebGL context</td><td>handled</td><td>The element is moved out of the canvas and shown as plain HTML with a message. It goes back when the context returns.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/stream/">Open Streamed HTML drawn as it arrives</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Page structure drawn in depth</title>
<link>https://html-in-canvas.page/structure-depth/</link>
<guid isPermaLink="true">https://html-in-canvas.page/structure-depth/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawable descendants</category>
<category>drawElementImage</category>
<category>section</category>
<category>nav</category>
<category>hr</category>
<category>details</category>
<category>aside</category>
<description>Sections on the faces of a cube, a &lt;nav&gt; along a moving ribbon, an article cut at its &lt;hr&gt; elements into slices at different depths, a &lt;header&gt; that folds away on scroll, &lt;details&gt; as a drawer cabinet and an &lt;aside&gt; that swings on a string. The buttons and links inside are pressed where they are drawn.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/structure-depth/"><img src="https://html-in-canvas.page/structure-depth/social.jpg" width="1200" height="630" alt="The page &quot;Page structure drawn in depth&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw the structural elements of a page (sections, nav, header, details, aside) in pieces and in depth, with the controls inside them still pressed where they are drawn?</p>
<p><strong>Short answer:</strong> Yes, with one extra step for an element shown in several pieces. An element has one hit region, so the page moves it to the piece under the pointer on <code>pointerdown</code>, with a draw at alpha 0 made outside the <code>paint</code> event.</p>
<p>
Six ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>, built. Each canvas draws structural elements
(<code>&lt;section&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;hr&gt;</code>, <code>&lt;header&gt;</code>, <code>&lt;details&gt;</code>, <code>&lt;aside&gt;</code>)
in a position the page layout doesn't have: on the faces of a cube, along a curve, at different depths, folded, pulled out towards the reader, and hanging from a string.
The elements stay in the document, and the buttons, links and checkboxes inside them are pressed where they are drawn. Drag the cube and the ribbon sideways, and scroll inside the two framed pages.
</p>
<h3>How it works</h3>
<p>Each canvas holds the real elements as descendants marked <code>drawable</code>. A <code>paint</code> handler draws them with <code>drawElementImage()</code> under a transform, or in clipped pieces under several transforms. The call also moves the element's hit region to where it was drawn. Four techniques are used more than once:</p>
<ul>
<li><b>Strips.</b> A 2D context has affine transforms only. Perspective (the cube, the inside of a drawer), a fold (the header) and a bend (the ribbon) are made by drawing the same element many times, each time clipped to a narrow strip with its own transform.</li>
<li><b>One region, several pieces.</b> An element has one hit region, at the place of its last draw. The article in slices and the open drawer are shown in pieces that no single transform covers. A <code>pointerdown</code> listener on the canvas, in the capture phase, finds the piece under the pointer and makes one draw of the element there with <code>globalAlpha = 0</code>. That draw is allowed outside a <code>paint</code> event and moves the region before the browser picks the target of the tap.</li>
<li><b>A canvas inside a scroller.</b> The folding header and the margin notes need a scroll position. The canvas is <code>position: sticky</code> in an ordinary scroller with a spacer under it, and draws the content at minus <code>scrollTop</code>. The browser scrolls it by touch, wheel and keyboard.</li>
<li><b>The element is the state.</b> The cabinet reads <code>open</code> on each paint and the notes read the scroll position. A closed <code>&lt;details&gt;</code> has no picture of its body, so the cabinet keeps a <code>captureElementImage()</code> snapshot of each open drawer and closes the old snapshot when it takes a new one.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, at 412 px wide with emulated touch, and at 1000 px wide with a mouse and a keyboard.</p>
<ul>
<li><b>An element has one hit region, and a canvas can move it before a tap is resolved.</b> A call to <code>drawElementImage()</code> with <code>globalAlpha = 0</code> made in a <code>pointerdown</code> listener, outside any <code>paint</code> event, moved the region. A touch tap sent with no delay between touch start and touch end then pressed the button in the piece under the finger: in the slices (button, checkbox) and in the drawer body (checkbox, range input, button).</li>
<li><b>The same draw needs an attribute toggle after it.</b> <code>elementFromPoint()</code> at the same point still returned the old answer until an attribute on the element changed. The check "A draw with globalAlpha 0 outside a paint event" shows both answers.</li>
<li><b>Two other routes for the same job were tried on a test page.</b> <code>updateElementGeometry()</code> in the <code>pointerdown</code> listener also worked. Asking for a paint and moving the region in the next <code>paint</code> event was too late for a tap with no delay (the click went to the canvas) and worked for a tap held for 60 ms.</li>
<li><b>A canvas that is <code>position: sticky</code> in a scroller is scrolled natively from its drawn content.</b> A touch drag that started on a drawn paragraph scrolled the scroller, a wheel did too, and the page didn't move. A scroll raises no <code>paint</code> event, so the page asks for one in its <code>scroll</code> listener. An element taller than the canvas, inside the canvas, didn't add to the scroll length.</li>
<li><b>Landmarks and headings stay in the accessibility tree.</b> Chromium's tree (read over the DevTools protocol) lists four regions named Overview, Plan, Sizes and Contact with their headings, the three <code>&lt;nav&gt;</code> elements as navigation landmarks, and all eight ribbon links, including the faces that are turned away and the links that are outside the canvas.</li>
<li><b>Focus can drive the drawing.</b> Tab from the first face moved focus into the second section, which was parked, and the <code>focusin</code> listener turned the cube to it.</li>
<li><b>A link drawn in turned strips is still a link.</b> Its one hit region is its box turned to the angle of the curve. A click on it navigated. A drag of more than 8 px pulled the ribbon and didn't navigate.</li>
<li><b><code>offsetTop</code> of an <code>&lt;hr&gt;</code> inside a positioned <code>drawable</code> article gives the cut.</b> A clipped draw of the article shows the rows between two cuts and nothing else.</li>
<li><b>A horizontal drag on a canvas with <code>touch-action: pan-y</code> reaches the page, and a vertical one scrolls it.</b> The drag turned the cube by two faces with no page scroll. A vertical swipe on the same face scrolled the page by the length of the swipe.</li>
<li><b>The open drawer hides the drawer below it.</b> Its front is drawn over the next slot and takes the taps there. That matches the picture, and it means the hidden drawer can't be opened until the open one is closed or another visible one is tapped.</li>
<li><b>Not verified:</b> everything on a phone. In particular whether a real finger tap is resolved after the <code>pointerdown</code> listener has moved the region, the frame rate of the ribbon (about 100 clipped draws a frame), the long-press link menu on a ribbon link, scroll momentum inside the two scrollers and how it drives the notes, and what TalkBack announces on the cube.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/structure-depth.md">findings/structure-depth.md</a> in the repository.</p>
<p>Measured in C157 (headless shell 157.0.8103.78) on 2026-11-21, at 412 px wide with emulated touch and at 1000 px wide with a mouse and a keyboard. Not yet run on A159. Input was sent by a Playwright script (touch through CDP <code>Input.dispatchTouchEvent</code> and <code>touchscreen.tap()</code>), which is not in the repository. The eight live checks on the page repeat the API results.</p>
<p>Six demos on one page, 2D canvas only, backlog group 17.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Four <code>&lt;section drawable&gt;</code> on a cube, drawn in 26 vertical strips per face while it turns</td><td>works</td><td>The front face is one flat draw at rest. While turning, the face most towards the reader gets one more draw at alpha 0 at its flat place and the other is parked.</td></tr>
<tr><td>Landmarks and headings of faces that are turned away</td><td>in the accessibility tree</td><td>CDP <code>Accessibility.getFullAXTree</code>: four <code>region</code> nodes named by their headings, three <code>navigation</code> nodes, four headings.</td></tr>
<tr><td>Tab into a section that is parked (scale 0.001)</td><td>works</td><td>Focus moves there, <code>focusin</code> fires, the page turns the cube to it.</td></tr>
<tr><td><code>&lt;a drawable&gt;</code> drawn in 4 px strips, each turned to the angle of a curve</td><td>works</td><td>Hit region: the link's box turned to the angle at its middle. <code>elementFromPoint()</code> returns the link, a click navigates, <code>href</code> is unchanged.</td></tr>
<tr><td>A drag that starts on a link</td><td>pulls the ribbon</td><td>Pointer capture is taken only after 8 px of movement, and the click that follows a drag is cancelled. A tap is left alone.</td></tr>
<tr><td>Cut an article at each <code>&lt;hr&gt;</code></td><td>works</td><td><code>hr.offsetTop + hr.offsetHeight</code>, with <code>position: relative</code> on the article. Each slice is the whole article under a clip.</td></tr>
<tr><td>One element drawn as several pieces, hit in every piece at once</td><td>fails</td><td>One hit region, at the last draw. Live check, expected fail.</td></tr>
<tr><td>Move the region on <code>pointerdown</code> with a draw at <code>globalAlpha = 0</code> outside a <code>paint</code> event</td><td>works</td><td>The draw is allowed outside <code>paint</code>. A touch tap with no delay then presses the control in the piece under the finger. An attribute toggle is needed after the draw.</td></tr>
<tr><td>Move the region on <code>pointerdown</code> with <code>updateElementGeometry()</code></td><td>works</td><td>Tried on a test page only. Not used, because the unit of <code>canvasTransform</code> has been seen to differ between canvases.</td></tr>
<tr><td>Move the region in the next <code>paint</code> event after <code>pointerdown</code></td><td>too late for a fast tap</td><td>With no delay between touch start and end the click went to the canvas. With 60 ms it worked.</td></tr>
<tr><td>A <code>position: sticky</code> canvas in a native scroller, content drawn at minus <code>scrollTop</code></td><td>works</td><td>Touch drag on drawn content and wheel scroll the scroller, not the page. Buttons in the article are hit where drawn.</td></tr>
<tr><td>Does a scroll of that scroller raise <code>paint</code>?</td><td>no</td><td>0 events in 300 ms. The <code>scroll</code> listener calls <code>requestPaint()</code>.</td></tr>
<tr><td>Does an element taller than the canvas, inside it, add to the scroller's length?</td><td>no</td><td><code>scrollHeight</code> 450 px for a 150 px canvas plus a 300 px spacer, with a 450 px element in the canvas.</td></tr>
<tr><td><code>&lt;header drawable&gt;</code> folded in four sheared strips by scroll distance</td><td>works</td><td>Parked while folded, one flat draw when open.</td></tr>
<tr><td>Open <code>&lt;details&gt;</code> drawn as two parts: body rows widening above, summary larger below</td><td>works</td><td>Region follows the pointer between the two parts. Checkbox, range input and button in the squashed body took touch taps.</td></tr>
<tr><td>Closing drawer</td><td>drawn from a snapshot</td><td><code>captureElementImage()</code> while open and at rest; the old snapshot is closed before a new one is taken.</td></tr>
<tr><td><code>&lt;aside drawable&gt;</code> drawn under a rotation about a pin</td><td>works</td><td>Client rect is the bounding box of the turned box (115.5 by 94.2 px for 100 by 60 at 0.4 rad). Its checkbox took a tap while it hung turned.</td></tr>
<tr><td><code>npm run check:jank -- /structure-depth/</code></td><td>passes</td><td>cls 0, 3.5 MB in canvases, 0.88 MP largest, 0 readbacks.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>A point-in-piece test in the page's own coordinates is needed before the browser's hit test, so the listener is on the canvas in the capture phase. The target of <code>pointerdown</code> itself is still chosen from the old region. Only the tap (click) that follows uses the new one.</li>
<li>A pendulum whose pin moves straight up or down does not swing. The notes are pushed sideways by the change in scroll speed (direction from the sign), and the real effect of the moving pin is only the stretch of the string.</li>
<li>The drawer that is out covers the slot below it and takes its taps. The body was made shorter (104 px, drawn at 0.7 of its height) so that only one slot is covered.</li>
<li><code>offsetTop</code> of a control inside a <code>&lt;details&gt;</code> in a canvas was not usable to find its place in the test script. The script used fractions of the drawn body.</li>
<li>An <code>&lt;aside&gt;</code> inside a <code>&lt;section&gt;</code> with no name is not a complementary landmark in Chromium's tree. The notes are therefore not listed as landmarks. That is ordinary HTML mapping, not an effect of the canvas.</li></ul>
<h3>Not verified</h3>
<ul><li>Everything on a phone (A159). Opening the page and using each demo would verify it. The most uncertain item: that a real finger tap is resolved after the <code>pointerdown</code> listener has moved the hit region (slices and drawer body).</li>
<li>Frame rate of the ribbon, about 100 clipped and turned draws a frame, and of the cube, 52 strips a frame while turning.</li>
<li>The long-press menu on a ribbon link ("Open in new tab").</li>
<li>Scroll momentum in the two inner scrollers, and how momentum scrolling pushes the notes.</li>
<li>TalkBack on the cube and the cabinet.</li>
<li>Loss of a context. The fallback to plain HTML was run with a dispatched <code>contextlost</code> event only.</li></ul>
<h3>Ideas built</h3>
<p>From <code>public/elements/ideas.js</code> (structure): "Sections on a cube", "Navigation on a ribbon", "Slices between hr elements", "Header that folds away", "Drawer cabinet from details", "Aside as a margin note on a string". PLAN.md backlog 17.1 to 17.6.</p>
<p><a href="https://html-in-canvas.page/structure-depth/">Open Page structure drawn in depth</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Tab switcher: live pages in a fan</title>
<link>https://html-in-canvas.page/tab-fan/</link>
<guid isPermaLink="true">https://html-in-canvas.page/tab-fan/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>iframe</category>
<category>drawElementImage</category>
<category>updateElementGeometry</category>
<category>BroadcastChannel</category>
<description>Four pages of a small app in same-origin iframes, drawn as a hand of cards. Every card is the running page and takes taps where it is drawn. A card's title bar opens it at full size, and a drag turns the fan.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/tab-fan/"><img src="https://html-in-canvas.page/tab-fan/social.jpg" width="1200" height="630" alt="The page &quot;Tab switcher: live pages in a fan&quot;"></a></p>
<p><strong>Question:</strong> Can the open pages of an app be shown as a fan of live, clickable cards, each one a same-origin iframe drawn rotated and scaled?</p>
<p><strong>Short answer:</strong> Yes. Rotated iframes take input at the drawn position and repaint the canvas when their document changes.</p>
<p>
Four pages of one small app, each in a same-origin <code>&lt;iframe&gt;</code> inside a canvas, drawn as a hand of cards. The cards are the running pages:
start the timer on one card and the others show the time, pick a colour in Settings and every card changes.
Tap inside a card to use the page. Tap a card's title bar to open it at full size, and tap the bar again to go back. Drag sideways on the bars or the background to turn the fan.
</p>
<h3>How it works</h3>
<p>Each iframe is laid out at 300 by 440 CSS pixels, so its page sees a phone-sized viewport at all times. On every <code>paint</code> event the canvas works out a pose for each card: a centre, an angle and a scale.
In the fan the centres lie on a circle whose middle is 380 pixels below the canvas, 11 degrees apart, at about 0.6 scale. <code>drawElementImage()</code> draws the iframe under that transform and puts its hit region there, so a tap on a rotated card reaches the page inside it at the right place.</p>
<p>A change inside any iframe raises the canvas's <code>paint</code> event, so the page runs no timer for the cards. The title in a card's bar is read from <code>iframe.contentDocument.title</code> on each paint. The Timer page puts the running time in its title.</p>
<p>The title bars and the close marks are drawn by the canvas and aren't elements. Pointer events over them go to the canvas, and the page maps the pointer into each card's own coordinates with the inverse of the card's matrix.</p>
<p>Opening a card blends its pose towards the middle of the canvas at the largest scale that fits. The other cards drop below the canvas, and their hit regions are shrunk to a point so they take no input. Where two cards overlap, the one drawn last is on top in the picture and also takes the tap.</p>
<p>The iframes are added and removed from click handlers, never inside the <code>paint</code> event: Chromium 157 crashes if an iframe is inserted or removed there.</p>
<h3>Findings</h3>
<ul>
<li>In Chromium 157 a same-origin iframe can be drawn rotated and scaled, and a tap at the drawn position reaches the document inside it. The frame's own layout size doesn't change, so the page inside doesn't reflow when its card grows.</li>
<li>A change in the framed document (a timer tick, typing, a colour set through a <code>BroadcastChannel</code> message) raises the outer canvas's <code>paint</code> event.</li>
<li>Where two drawn iframes overlap, the one drawn last takes the tap, in either document order. With a 2D canvas the picture and the hit testing agree without extra work.</li>
<li><code>contentDocument.title</code> is readable during <code>paint</code>, so the bars follow title changes with no message passing.</li>
<li>The frames keep running while their card is dropped out of view. Nothing in the API pauses a frame that isn't drawn.</li>
<li>This works for same-origin pages only. A cross-origin iframe is drawn as transparent pixels (measured on <a href="https://html-in-canvas.page/iframe-tiles/">/iframe-tiles/</a>).</li>
<li>Not verified: text entry in a rotated card with the on-screen keyboard, scrolling inside a rotated card by touch, and how many live iframes a phone keeps drawing at 60 frames per second.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/tab-fan.md">findings/tab-fan.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, 412 px wide, touch emulation) on 2026-11-21. Not yet run on A159.</p>
<p>Four to seven same-origin iframes are canvas children with <code>drawable</code>. Each holds a page from <code>/tab-fan/app/</code>. The pages share state over a <code>BroadcastChannel</code>.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Same-origin iframe drawn rotated and scaled</td><td>works</td><td>100% ink in the middle of a card rotated by 20 degrees.</td></tr>
<tr><td>Tap inside a rotated card</td><td>reaches the framed page at the right place</td><td>A touch tap on the Start button of the Timer card, drawn rotated at 0.63 scale, started the timer. Two seconds later the Notes card's footer showed "Timer 00:02".</td></tr>
<tr><td>Typing in the open card</td><td>works</td><td>Tap the textarea in the Notes card and type: the character count in the frame went from 47 to 50.</td></tr>
<tr><td>A change inside the framed document</td><td>raises the outer canvas's <code>paint</code> event</td><td>Timer ticks, typing and a colour set by a channel message. The page runs no timer for the cards.</td></tr>
<tr><td><code>iframe.contentDocument.title</code> inside <code>paint</code></td><td>readable</td><td>The title bars are drawn from it.</td></tr>
<tr><td>Two drawn iframes overlap</td><td>the one drawn last is hit</td><td>Tested in both document orders. In a 2D canvas the picture and the hit testing agree. This differs from the note "hit testing follows document order" recorded for WebGL geometry on <code>/carousel/</code>.</td></tr>
<tr><td>Layout size of a frame while its card grows</td><td>unchanged</td><td>The iframe stays 300 by 440 CSS px. Only the drawn scale changes, so the framed page does not reflow.</td></tr>
<tr><td>Cards dropped below the canvas</td><td>keep running</td><td>Their hit regions are parked at a point with <code>updateElementGeometry()</code>.</td></tr>
<tr><td>Adding and removing iframes from click handlers</td><td>no crash</td><td>Never inside <code>paint</code>: that crashes Chromium 157 (recorded on <code>/iframe-tiles/</code>). Live checks leave the <code>paint</code> event with a timer before the harness removes a fixture.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The title bars are canvas drawing, so the page hit tests them with the inverse of each card's matrix. <code>ctx.getTransform()</code> is in canvas pixels, so the pointer position is multiplied by <code>canvas.width / canvas.clientWidth</code> first.</li>
<li>A drag that starts on a card belongs to the framed page. The fan turns only from a drag that starts on a bar or the background, or from the arrow buttons.</li></ul>
<h3>Not verified</h3>
<ul><li>Text entry in a rotated card with the on-screen keyboard, and scrolling inside a rotated card by touch.</li>
<li>How many live iframes a phone keeps drawing smoothly. "Open another page" goes up to seven.</li>
<li>Whether Android throttles or freezes frames whose cards are parked.</li></ul>
<h3>Ideas built</h3>
<ul><li>"Tab switcher of live pages" from <code>public/elements/ideas.js</code> (frames).</li></ul>
<h3>Open ideas</h3>
<ul><li>Navigation inside a card (<code>&lt;a href&gt;</code> between the app pages) with the bar following <code>contentDocument.title</code> and a back mark that calls <code>contentWindow.history.back()</code>.</li>
<li>The same fan in 3D through <code>lib/element-gl.js</code>, with perspective on the cards.</li></ul>
<p><a href="https://html-in-canvas.page/tab-fan/">Open Tab switcher: live pages in a fan</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Tables and blocks: caption, tfoot, time, data, address and marquee</title>
<link>https://html-in-canvas.page/table-data/</link>
<guid isPermaLink="true">https://html-in-canvas.page/table-data/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>caption</category>
<category>tfoot</category>
<category>time</category>
<category>data</category>
<category>address</category>
<category>marquee</category>
<category>drawElementImage</category>
<description>A table caption that comes down as a red rubber stamp, a footer total that counts to its new value, the datetime and value attributes drawn above their elements, an &lt;address&gt; drawn on an envelope that seals and leaves, and a &lt;marquee&gt; of links drawn as a board of lit dots.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/table-data/"><img src="https://html-in-canvas.page/table-data/social.jpg" width="1200" height="630" alt="The page &quot;Tables and blocks: caption, tfoot, time, data, address and marquee&quot;"></a></p>
<p><strong>Question:</strong> A caption, a tfoot, a time and a data element aren't drawable by themselves, and a marquee moves on its own. Can a canvas restyle each from the picture of its parent, and keep a moving marquee's links working?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. A caption and a tfoot have boxes inside the table's picture, and a clipped draw moves one alone; ctx.filter turns the caption red. datetime and value aren't in the picture and are drawn as canvas text. A drawable marquee raised 60 paint events a second and none after stop(), and elementFromPoint() found a moving link in 10 of 10 samples.</p>
<p>
Five ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a> about elements that carry a fact: the caption and the footer of a table,
the machine form of a date or a number, a postal address, and a line of links that scrolls. In each demo the element stays in the
document with its own text, and the canvas draws it somewhere else or draws around it.
</p>
<h3>How it works</h3>
<ul>
<li><b>One drawable block per effect.</b> A caption, a footer and a <code>&lt;time&gt;</code> aren't <code>drawable</code>: they're parts of the picture of the table or paragraph around them. A part is drawn by clipping a draw of the whole block to the part's box (<code>offsetLeft</code>, <code>offsetTop</code>, <code>offsetWidth</code>, <code>offsetHeight</code>).</li>
<li><b>Where input goes.</b> A block that is drawn in pieces is placed once more at the end with a draw that is clipped away completely. That draw puts no pixels on the canvas and sets the hit region.</li>
<li><b>Frames.</b> The first four demos ask for frames only while something moves. The ticker never asks: the marquee's own repaints are its clock.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.</p>
<ul>
<li><b>A caption and a table footer can be moved as pictures by clipping.</b> Neither is <code>drawable</code> by itself. In a table with <code>position: relative</code> the caption was at 0, 0 and 200 by 24 px, and the <code>tfoot</code> at 0, 76 and 200 by 26 px. A draw of the table clipped to one of those boxes moves that part alone. With <code>caption-side: bottom</code> the caption's box is under the footer (78 against 52).</li>
<li><b>A caption's box is as wide as the table.</b> The words in it were 33 px of 200. The stamp uses the box of a <code>&lt;span&gt;</code> inside the caption.</li>
<li><b><code>ctx.filter</code> recolours a clipped piece.</b> <code>brightness(0) invert(0.45) sepia(1) saturate(30) hue-rotate(-40deg)</code> on the draw of the caption gave red letters, with no readback and no second canvas.</li>
<li><b>Text written into a cell on every frame keeps up.</b> Five changes of a <code>tfoot</code> cell 100 ms apart raised five paint events that name the table. In the demo the cell's text is the count, so the canvas has nothing to draw over it.</li>
<li><b><code>datetime</code> and <code>value</code> aren't in the picture.</b> A block was 220 by 24 px with and without them. They're read from <code>time.dateTime</code> and <code>data.value</code> and drawn as canvas text at the element's first client rectangle.</li>
<li><b>A drawable <code>&lt;marquee&gt;</code> is a clock.</b> It raised 60 paint events in one second while it scrolled and none after <code>stop()</code>. The ticker has no <code>requestAnimationFrame()</code> call and no timer.</li>
<li><b>Links in a scrolling marquee are hit-tested where they are.</b> <code>elementFromPoint()</code> found a moving link in 10 of 10 samples while its left edge went from 113 to -22 px. The board is drawn with two blurred copies, a reflection and a dot mask, and the last draw of the marquee is a clipped-away one at its upright place.</li>
<li><b>An <code>&lt;address&gt;</code> and its form can share a canvas.</b> A tap on the drawn Town field focused that field, and typed text reached the address on the envelope on the next paint.</li>
<li><b>Not verified:</b> everything on a phone. The speed of the ticker's three filtered draws at 60 paint events a second, the on-screen keyboard over the envelope form, and holding a finger on the button of the third demo without a long-press menu.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/table-data.md">findings/table-data.md</a> in the repository.</p>
<p>Backlog group 28 in PLAN.md, ideas 28.12, 28.13, 28.14, 28.16 and 28.20. Measured in headless Chromium 157 (C157) on 2026-11-21 at 412 px wide. The page's five live checks pass there, and <code>node tools/table-data/check.mjs</code> drives the five demos by touch (29 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: a caption, a tfoot, a time and a data element are not drawable by themselves, and a marquee moves on its own. Can a canvas restyle each from the picture of its parent, and keep a moving marquee's links working?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Boxes of <code>caption</code> and <code>tfoot</code> in a drawable table with <code>position: relative</code></td><td>caption 0, 0, 200 by 24 px; tfoot 0, 76, 200 by 26 px</td><td>Offset boxes measured from the table's corner. A draw of the table clipped to one of them moves that part alone.</td></tr>
<tr><td>The same table with <code>caption-side: bottom</code></td><td>caption at 0, 78, tfoot at 52</td><td>The caption's box is under the footer.</td></tr>
<tr><td>Width of a caption against its words</td><td>caption 200 px, a <code>span</code> of its words 33 px</td><td>A caption is as wide as the table. The stamp uses the span's box (119 by 19 px in the demo).</td></tr>
<tr><td><code>ctx.filter = 'brightness(0) invert(0.45) sepia(1) saturate(30) hue-rotate(-40deg)'</code> on a clipped draw of the caption</td><td>red letters (seen in a screenshot, not read back)</td><td>Caption as a rubber stamp (28.12): turned 15 degrees, 1.9 times its size, down in 0.25 s. The link in the last row is still found by <code>elementFromPoint()</code> under the stamp.</td></tr>
<tr><td>A <code>tfoot</code> cell's text changed 5 times, 100 ms apart</td><td>5 paint events that name the table</td><td>Footer totals that count up (28.13): the cell's text is written on each frame for 0.6 s. The total read £34.44 0.25 s into a count from £24.25 to £37.00.</td></tr>
<tr><td>Buttons and inputs in table cells, table drawn in two clipped pieces</td><td>a tap on a drawn + button and typing into a drawn input both changed the total</td><td>The table is placed once more with a clipped-away draw, which sets the hit region.</td></tr>
<tr><td>A block with and without <code>datetime</code> on its <code>time</code> and <code>value</code> on its <code>data</code></td><td>220 by 24 px both times, <code>time</code> 57 px wide both times</td><td>Machine values next to shown values (28.14) reads <code>dateTime</code> and <code>value</code> and draws them as canvas text above the first client rectangle of each element.</td></tr>
<tr><td>Paint events naming a drawable <code>marquee</code> (<code>scrollamount="3" scrolldelay="16" truespeed</code>)</td><td>60 in one second, 0 in half a second after <code>stop()</code></td><td>Stock ticker with real links (28.20) draws only on those events.</td></tr>
<tr><td><code>elementFromPoint()</code> at a link inside the scrolling marquee, 10 samples 80 ms apart</td><td>10 of 10 found the link, left edge from 113 to -22 px</td><td>Hit testing follows the scroll. In the demo a touch tap on a moving link reported that link.</td></tr>
<tr><td>An <code>address</code> and a <code>form</code>, both drawable, in one canvas</td><td>a tap on the drawn Town field focused it; typing changed the address on the envelope</td><td>Address on an envelope (28.16). On submit the flap closes in 0.5 s and the envelope leaves; no frames afterwards.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the five canvases and shows the elements as plain HTML (5 boxes). The ticker uses the paint handler of <code>/paint-clocks/</code> and the others that of <code>/form-state/</code>, so the page passes each kit's stop event to the other. Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The stamp was first sized from the caption's own box and came out as wide as the table times 1.9. The caption's box spans the table.</li>
<li>The M key did nothing after a tap on the "Keep them shown" box, because the key handler ignored every <code>input</code> and the checkbox had focus. It now ignores text fields only.</li>
<li>The tool script looked for a link inside the marquee at one moment and found the gap at the end of the loop. It now waits up to 8 s.</li>
<li><code>put()</code> from one kit and <code>mount()</code> from the other do not share the flag that asks for a retry when an element has no picture yet. The ticker imports both from <code>/paint-clocks/kit.js</code>.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the five demos by touch.</li>
<li>The cost of the ticker on a phone: three filtered draws of the marquee on each of 60 paint events a second.</li>
<li>The on-screen keyboard over the envelope form and the quantity fields.</li>
<li>Holding a finger on the "Hold to show machine values" button without a long-press menu or text selection.</li>
<li>Whether a real marquee on Android scrolls at the same rate (<code>truespeed</code> with a 16 ms delay).</li>
<li>The colour of the stamp was judged from a screenshot, not from pixel values.</li></ul>
<p><a href="https://html-in-canvas.page/table-data/">Open Tables and blocks: caption, tfoot, time, data, address and marquee</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Screen capture with HTML annotation tools in one canvas</title>
<link>https://html-in-canvas.page/telestrator/</link>
<guid isPermaLink="true">https://html-in-canvas.page/telestrator/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>getDisplayMedia</category>
<category>PointerEvent</category>
<category>captureStream</category>
<category>WebRTC</category>
<category>Region Capture</category>
<description>A telestrator. The screen, the camera or a clip is the video in a canvas. Pen strokes, arrows, notes, a magnifier, a spotlight and a redact box are DOM elements over it, and the canvas goes out as one stream.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/telestrator/"><img src="https://html-in-canvas.page/telestrator/social.jpg" width="1200" height="630" alt="The page &quot;Screen capture with HTML annotation tools in one canvas&quot;"></a></p>
<p><strong>Question:</strong> Can a screen capture be the video under HTML annotation tools in one drawable canvas, with the annotations made of DOM, and can the result be sent on as one stream and recorded?</p>
<p><strong>Short answer:</strong> Yes. The capture is a <code>&lt;video&gt;</code> like any other, the annotations are SVG paths and form controls that keep working, and the redaction is in the stream. A capture cropped to the canvas itself is a closed loop.</p>
<p>
The picture is one 2D canvas with two <code>drawable</code> children: a <code>&lt;div&gt;</code> that holds a <code>&lt;video&gt;</code>, and a layer of annotations made of DOM.
Draw on it with a finger, a pen or a mouse. The magnifier, the spotlight and the redact box change the video pixels under them.
The video can be the test clip, the screen or the camera, and the canvas goes out as one stream.
</p>
<h3>How it works</h3>
<ul>
<li>The canvas buffer is 640 by 360 on every screen. Both children are laid out at that size and drawn with <code>drawElementImage(el, 0, 0, canvas.width, canvas.height)</code>, which scales their hit boxes with their pictures.</li>
<li>Every annotation is an element in the layer: an SVG <code>&lt;path&gt;</code> for a stroke or an arrow, a <code>&lt;div&gt;</code> with a <code>&lt;textarea&gt;</code> for a note, a <code>&lt;div&gt;</code> for a step marker, a spotlight, a magnifier and a redact box.</li>
<li>The paint handler reads the boxes of the spotlight, magnifier and redact elements. Between the two <code>drawElementImage()</code> calls it draws regions of the same <code>&lt;video&gt;</code> again with <code>drawImage()</code>: grey and dark outside a spotlight, 2.2 times larger inside a magnifier, 14 px cells, a blur or black inside a redact box.</li>
<li>The handler has no render loop. The video raises <code>paint</code> for each frame, and a DOM change or a CSS animation in the layer raises it too.</li>
<li>A screen capture is a <code>MediaStream</code> in the video's <code>srcObject</code>. Nothing else on the page changes when the source changes.</li>
<li>The outgoing stream is <code>canvas.captureStream(30)</code>. The redaction is made in the canvas, so no reader of the stream gets the pixels under the box.</li>
</ul>
<h3>Findings</h3>
<p>Measured on 2026-11-21. The canvas, the tools and the stream: Chromium 157 headless with software rendering. A real capture of a tab: Chromium 153 with a window, because the headless build can't start one. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: a display capture as the video.</strong> A <code>getDisplayMedia()</code> stream in <code>srcObject</code> is drawn by <code>drawElementImage()</code> and by <code>drawImage(video)</code> like any other video. The canvas isn't tainted: <code>getImageData()</code> and <code>captureStream()</code> work on it.</li>
<li><strong>Works: annotations as DOM.</strong> A stroke is an SVG <code>&lt;path&gt;</code>, and a note is a <code>&lt;textarea&gt;</code> that takes a tap, a caret and typing inside the canvas. Two <code>drawable</code> children drawn with a size each keep their own hit boxes, so the layer takes the pointer events and nothing else is needed.</li>
<li><strong>Works: annotations that change the video.</strong> The paint handler draws regions of the video between the two element draws. The magnifier is drawn from the video's own pixels, not from the 640 px canvas. The redaction is in the canvas pixels, so it is in the recording and in the WebRTC stream.</li>
<li><strong>Needed: redact inside the magnifier too.</strong> The magnifier reads the video, not the canvas. The paint handler therefore redacts a second time inside each lens. The fourth live check counts 0 pixels of a redacted mark under a lens.</li>
<li><strong>Works: fading with no script.</strong> A CSS opacity animation on a path raised 28 <code>paint</code> events in the 450 ms in which the opacity changed, and none while the keyframes held it at 1.</li>
<li><strong>Works: pressure.</strong> Touch points sent with a rising force gave a path that is a ribbon of varying width. Points that all carry one pressure give a plain stroked line.</li>
<li><strong>Works: capturing the tab that holds the canvas.</strong> With <code>preferCurrentTab</code> the video shows the page with the canvas in it, and the picture repeats inside itself. No crash.</li>
<li><strong>Limit: a capture cropped to the canvas is a closed loop.</strong> After <code>track.cropTo()</code> or <code>track.restrictTo()</code> with the canvas as the target, the video holds only the canvas, which draws only the video. The picture from before the crop stayed, and each annotation was drawn over its own copy on every frame. Crop to another element, not to the canvas.</li>
<li><strong>Limit: <code>cropTo()</code> and <code>restrictTo()</code> are for this tab only.</strong> On a capture of another tab both threw <code>NotAllowedError: Invalid target</code>. On a monitor capture the track is a plain <code>MediaStreamTrack</code> with neither method.</li>
<li><strong>Limit: scroll and zoom of the captured tab need a tab and a permission.</strong> <code>forwardWheel()</code> and <code>increaseZoomLevel()</code> threw <code>NotSupportedError</code> on a monitor capture. On a tab capture both stayed pending in the automated browser, which is what an unanswered permission prompt does.</li>
<li><strong>Limit: Chrome on Android.</strong> This page reads <code>navigator.mediaDevices.getDisplayMedia</code> and turns the Screen and This tab buttons off when it's missing. The clip and the camera use the same canvas and tools.</li>
<li><strong>Limit: the canvas has to be on screen.</strong> A recording made while the canvas was scrolled out of the window was 0 kB.</li>
<li><strong>Not verified here:</strong> a real stylus, touch on a phone, the picker and sharing bar of a real desktop Chrome, <code>setFocusBehavior()</code> with a visible window switch, and the frame rate of a 4K capture. The first live check lists what your browser has, and the log under the source buttons writes what each call did.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/telestrator.md">findings/telestrator.md</a> in the repository.</p>
<p>Chromium 157 headless (C157), software rendering and software video decoding, 2026-11-21, for the canvas, the tools, the stream and the live checks. Chromium 153 with a window under Xvfb (C153, <code>channel: 'chromium'</code>, <code>--enable-features=CanvasDrawElement --enable-blink-features=CanvasDrawElement</code>), same date, for every row that needed a real display capture: the C157 headless shell cannot start one. Nothing here was run on a phone or on desktop Chrome with a person at it.</p>
<p>The page is one 2D canvas with a 640×360 buffer and two <code>drawable</code> children: a <code>&lt;div&gt;</code> that holds the <code>&lt;video&gt;</code>, and a layer of annotations. The paint handler draws the first child, then regions of the video with <code>drawImage(video, sx, sy, …)</code> and <code>ctx.filter</code>, then the layer.</p>
<h3>The canvas and the tools</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Two <code>drawable</code> children, both <code>position: absolute</code> at 0,0 and 640×360, each drawn with <code>drawElementImage(el, 0, 0, canvas.width, canvas.height)</code></td><td>works, measured C157</td><td>Pointer events reach the elements of the upper child. No <code>updateElementGeometry()</code> call.</td></tr>
<tr><td><code>drawImage(video, sx, sy, sw, sh, …)</code> of a canvas child <code>&lt;video&gt;</code> inside the <code>paint</code> handler, between the two element draws</td><td>works, measured C157</td><td>Used for the magnifier, the spotlight and the redaction. One decoder, no second video.</td></tr>
<tr><td>Pen stroke as one SVG <code>&lt;path&gt;</code> in the layer</td><td>in the canvas, in the <code>MediaRecorder</code> file and in the WebRTC stream, measured C157</td><td>Check 2: 255,0,255 on the stroke in the canvas and in the file. Check 6: 255,0,255 on the stroke and 0,201,0 on the video after WebRTC, 320×180 at 25 frames a second.</td></tr>
<tr><td>Glow colour from the video under the stroke</td><td>works, measured C157</td><td>A 64×36 <code>drawImage(video)</code> copy is read at the stroke's points. Over 0,200,0 the hue read was 120 and the pixel 5 px beside the stroke was 18,216,18. The glow is two CSS <code>drop-shadow()</code> filters on the path.</td></tr>
<tr><td><code>PointerEvent.pressure</code> to stroke width</td><td>a ribbon path when the pressure varies, measured C157</td><td>Touch points dispatched through CDP with a force rising from 0.2 to 1 gave a 21 point filled outline path. Points with one pressure give a stroked centre line. The pressure values of a real stylus are not verified.</td></tr>
<tr><td>Touch drag on the canvas with <code>touch-action: none</code></td><td>the page did not scroll (<code>scrollY</code> 0), measured C157 with emulated touch</td><td></td></tr>
<tr><td><code>&lt;textarea&gt;</code> note: tap with the Note tool, then type</td><td>focus went to the <code>&lt;textarea&gt;</code> and the typed text was its value, measured C157</td><td>Playwright keyboard input on the visible demo. Check 5 sets the value by script and reads the drawn text.</td></tr>
<tr><td>Note shown at half size, then moved 60 px</td><td>hit where drawn before and after the move, measured C157</td><td>Check 5. The <code>&lt;textarea&gt;</code> box on screen is 105×24 px, half its layout size.</td></tr>
<tr><td>Step marker, spotlight, magnifier, redact box by tap or drag, Move, Erase, Undo, Clear</td><td>work, measured C157 with emulated touch</td><td>Erase finds strokes by distance to their points, not by SVG hit testing.</td></tr>
<tr><td>Fade mode: CSS opacity animation on the path</td><td>raises <code>paint</code> with no <code>requestPaint()</code>, measured C157</td><td>Check 7: 0 events in 600 ms with a still stroke, 0 in the 550 ms the keyframes hold opacity at 1, 28 in the 450 ms in which it changes. The path is removed on <code>animationend</code>.</td></tr></tbody></table>
<h3>Annotations that change the video</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Redact box, read from <code>canvas.captureStream()</code></td><td>the source pixel is gone in all three styles, measured C157</td><td>Check 3. A 4 px red mark (255,0,0): 255,254,254 with 14 px cells, 213,206,206 with <code>ctx.filter = 'blur()'</code>, 0,0,0 with black, 255,0,0 again when the box is removed.</td></tr>
<tr><td>Pixelation by <code>drawImage()</code> down to one pixel per cell with <code>imageSmoothingQuality</code> left at its default, then up with smoothing off</td><td>works</td><td>The 4 px mark was not visible in its cell. Whether a mark as large as a cell is averaged or sampled was not measured.</td></tr>
<tr><td>Magnifier: video region drawn 2.2 times larger inside a clipped circle</td><td>works, measured C157</td><td>Check 4: 16 red pixels plain, 64 under the lens.</td></tr>
<tr><td>Magnifier over a redact box</td><td>0 red pixels, measured C157</td><td>The lens reads the video, so the paint handler redacts again inside each lens. Without that pass the lens would draw the hidden region enlarged (inferred from the code, not run).</td></tr>
<tr><td>Spotlight: <code>clip('evenodd')</code> then the frame with <code>ctx.filter = 'grayscale(1) brightness(.35)'</code></td><td>works, seen in a screenshot, C157</td><td>No check reads it.</td></tr></tbody></table>
<h3>Sources and capture options</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Clip, then camera, then clip</td><td>works, measured C157</td><td>Chromium's fake camera, 640×360.</td></tr>
<tr><td><code>getDisplayMedia()</code> in the C157 headless shell</td><td><code>NotReadableError: Could not start video source</code> with <code>--use-fake-ui-for-media-stream</code> and <code>--auto-select-desktop-capture-source=Entire screen</code> or <code>--auto-accept-this-tab-capture</code>. <code>NotSupportedError: Not supported</code> with only <code>--auto-select-tab-capture-source-by-title</code></td><td>measured C157</td></tr>
<tr><td>The same with <code>--use-fake-device-for-media-stream</code> added</td><td>resolves with a fake monitor: plain <code>MediaStreamTrack</code> "screen:-3:0", <code>displaySurface</code> monitor, 1082×610, the fake camera pattern</td><td>measured C157. It is drawn in the canvas and the tools work on it. <code>preferCurrentTab: true</code> was accepted and still gave this monitor.</td></tr>
<tr><td>On that monitor track: <code>cropTo</code>, <code>restrictTo</code></td><td>the track has neither method</td><td>measured C157</td></tr>
<tr><td>On that monitor track: <code>controller.forwardWheel(canvas)</code>, <code>increaseZoomLevel()</code></td><td><code>NotSupportedError: Action only supported for tab-capture</code></td><td>measured C157</td></tr>
<tr><td><code>{ preferCurrentTab: true, selfBrowserSurface: 'include' }</code> with <code>--auto-accept-this-tab-capture</code>, C153 with a window</td><td>resolves: <code>BrowserCaptureMediaStreamTrack</code>, <code>displaySurface</code> browser, 800×900 (the viewport), cursor motion</td><td>measured C153</td></tr>
<tr><td>The canvas drawing a capture of its own tab</td><td>the page with the canvas in it, repeated inside itself; no crash</td><td>measured C153, screenshot. The canvas's place in the frame differed from the canvas by a mean of 35.6 of 255 per channel (the copy is one generation behind and smaller). <code>getImageData()</code> on a copy of the canvas worked, so the capture does not taint.</td></tr>
<tr><td><code>CropTarget.fromElement(canvas)</code>, <code>track.cropTo()</code> on that track</td><td>resolved in 1 ms; the video became 640×360</td><td>measured C153</td></tr>
<tr><td><code>RestrictionTarget.fromElement(canvas)</code>, <code>track.restrictTo()</code></td><td>resolved in 12 ms; the video was still 800×900 0.5 s later and 640×360 at the next reading</td><td>measured C153. The canvas has <code>isolation: isolate</code>.</td></tr>
<tr><td>Picture after the crop or the restriction to the canvas</td><td>a closed loop</td><td>measured C153, screenshots. The frame is only the canvas and the canvas draws only the frame. The page picture from before the crop stayed, and the arrow's glow grew on each pass because the arrow is drawn over its own copy. Mean difference between frame and canvas 17.0 and 16.5.</td></tr>
<tr><td><code>cropTo(null)</code>, <code>restrictTo(null)</code></td><td>both resolve</td><td>measured C153</td></tr>
<tr><td>Capture of another tab (<code>--auto-select-tab-capture-source-by-title</code>), then <code>cropTo()</code> and <code>restrictTo()</code> with the canvas</td><td>resolves as <code>BrowserCaptureMediaStreamTrack</code>, browser, 800×900; both calls throw <code>NotAllowedError: Invalid target</code></td><td>measured C153. The picture of the other tab in the canvas was not inspected.</td></tr>
<tr><td><code>forwardWheel(canvas)</code>, <code>increaseZoomLevel()</code> on a tab capture (other tab and own tab)</td><td>neither promise settled in 3 s</td><td>measured C153. Consistent with a permission prompt that nothing answered. Not verified further.</td></tr>
<tr><td><code>setFocusBehavior('no-focus-change')</code> before the call</td><td>no exception; effect not verified</td><td>The log line was overwritten in the run that used it; the page now writes it after the call line.</td></tr>
<tr><td>Same-size stand-in for self capture: the canvas's own <code>captureStream()</code> in its child video at half size</td><td>nesting levels 0 to 3 drawn; a removed stroke left level 0 after 65 ms, level 1 after 65 ms, level 2 after 133 ms; no crash</td><td>measured C157, check 8</td></tr>
<tr><td><code>getDisplayMedia</code> missing</td><td>the page disables Screen and This tab and says so</td><td>Code path not run: both test browsers have the method.</td></tr></tbody></table>
<h3>Output</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>"Record 5 s" with the clip, canvas on screen</td><td>998 kB of <code>video/webm;codecs=vp9,opus</code> with the clip's sound</td><td>measured C157</td></tr>
<tr><td>"Record 5 s" and "Send as one stream" with the canvas scrolled out of the window</td><td>0 kB; 2 frames decoded at the far end in 3.5 s</td><td>measured C157. The clip is paused by the page's IntersectionObserver there, and <code>requestPaint()</code> every 100 ms produced no frames. Which of the two stops it was not separated.</td></tr>
<tr><td>Live checks</td><td>8 of 8 pass</td><td>C157, 412 px wide, touch, device scale factor 2.625</td></tr>
<tr><td><code>node tools/jank/check.mjs --base … /telestrator/</code> and with <code>--checks</code></td><td>both pass</td><td>cls 0 and 0.001</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The redact box's own label ("hidden", black background) lay over the pixel the first version of check 3 read, so all three styles read 0,0,0. The mark is now in the lower half of the box.</li>
<li>The fade keyframes hold opacity at 1 for the first 55%. Nothing is painted in that time, so a paint count over the first 600 ms of a 1 s fade was 2.</li>
<li>A video whose <code>srcObject</code> is the canvas's own <code>captureStream()</code> showed nothing until <code>play()</code> was called on it.</li>
<li><code>--use-fake-device-for-media-stream</code> also replaces the display capture with the fake camera pattern labelled as a monitor. It looks like a pass and is not a screen capture.</li>
<li>A <code>Promise.race()</code> with a timer logged "has not settled" after the call had already rejected. The timer now checks a flag.</li></ul>
<h3>Not verified</h3>
<ul><li>Anything on Chrome 159 on Android: touch drawing, the note with the phone keyboard, the camera, the disabled Screen button. The live checks and the log under the source buttons report it on the device.</li>
<li>A real stylus: pressure range and the look of the ribbon. Draw with the Pen tool.</li>
<li>Desktop Chrome with a person: the picker, the sharing bar, <code>displaySurface</code> and <code>selfBrowserSurface</code> changing what the picker offers, <code>setFocusBehavior()</code>, the permission prompt and the effect of <code>forwardWheel()</code> and zoom. The Screen button with the options, then the buttons under "Capture options", write each result in the log.</li>
<li>The crop and restriction rows on Chromium 157 or later. They were measured on Chromium 153. The "This tab" button, then "Crop to the canvas" and "Measure the picture", repeat them.</li>
<li>Frame rate and cost with a 1920 px or 4K capture and several annotations.</li>
<li>Whether an off-screen canvas alone (video still playing) stops the stream.</li>
<li>System audio from <code>getDisplayMedia({ audio: true })</code> in the recording. The page asks for video only.</li></ul>
<h3>Further experiments</h3>
<ul><li>Crop the self capture to a sibling element (the page content beside the canvas) and annotate that, so the page annotates itself with no loop.</li>
<li>Send the annotations as DOM over a data channel beside the raw capture, and compose at the receiver, so the viewer can select the note text. Compare with the single composed stream.</li>
<li>A WebGPU route with <code>importExternalTexture(video)</code> for the magnifier at capture resolution.</li>
<li>Recognise the text under a redact box before hiding it (<code>TextDetector</code>) and redact by match.</li></ul>
<p><a href="https://html-in-canvas.page/telestrator/">Open Screen capture with HTML annotation tools in one canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Text measured by CSS for signs, labels and particles</title>
<link>https://html-in-canvas.page/text-labels/</link>
<guid isPermaLink="true">https://html-in-canvas.page/text-labels/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>text-fit</category>
<category>text-box-trim</category>
<category>createValueRange</category>
<category>drawElementImage</category>
<description>A neon sign, book spines and a ticker sized by text-fit and text-box-trim, and a real input in the canvas whose characters grow in, fly to the sign and break apart when deleted.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/text-labels/"><img src="https://html-in-canvas.page/text-labels/social.jpg" width="1200" height="630" alt="The page &quot;Text measured by CSS for signs, labels and particles&quot;"></a></p>
<p><strong>Question:</strong> Can CSS do the text measuring for a canvas: fit and trim a label to a box, and report the box of each character in an input?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. <code>text-fit</code> and <code>text-box-trim</code> size the drawn element, and <code>input.createValueRange()</code> gives a box per character that matches the drawn ink.</p>
<p>
Type in the field at the bottom of the picture. It's a real <code>&lt;input&gt;</code> drawn by the canvas. Each character you type
grows into place and a copy flies up to the sign, and each character you delete breaks into pieces. The canvas knows where each
character is from <code>input.createValueRange()</code>. The sign, the book spines and the ticker are elements sized by
<code>text-fit</code> and <code>text-box-trim</code>, drawn at the size CSS gave them.
</p>
<h3>How it works</h3>
<ul>
<li>The picture is one 2D canvas. Every label and the input are drawn with <code>drawElementImage()</code> at their <code>offsetWidth</code> and <code>offsetHeight</code>.</li>
<li>The sign is 250 px wide in CSS. <code>text-fit: grow</code> scales whatever you type to that width, and <code>text-box: trim-both cap alphabetic</code> makes its box end at the top of the capitals and at the baseline. "Show boxes" outlines each element's box. Turn "Trim" off to see the box that the same text has without it.</li>
<li>The book spines use <code>writing-mode: sideways-lr</code>. Each is 132 px along the spine, and <code>text-fit</code> picks the font size, so a short title is drawn large and its book is thick.</li>
<li>After each frame in which the field changed, the field's part of the canvas is copied to a second canvas and one rectangle per character is read. A deleted character is cut from that copy as 4 px pieces. A new character is drawn again from the copy: its dark pixels become a coloured, see-through picture of the letter, which is drawn large over the field and once more on a path to the sign.</li>
<li>The effects draw over the field. The field itself is drawn where the canvas says it is, so a tap focuses it and the caret and selection are the browser's.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: <code>text-fit</code> in the picture.</strong> The fitted size is what is drawn, and it follows edits and a CSS animation of <code>font-weight</code> with no script. The element's height follows the fitted size, so a short text makes a tall label. This page caps the sign's drawn height at 96 px by scaling the draw.</li>
<li><strong>Works: <code>text-box-trim</code> makes the box the ink.</strong> With <code>cap alphabetic</code> the first row of the element's picture has ink in it. Descenders and accents fall outside the box and are cut off by the element's picture, which is the stated behaviour of the property and matters for a texture.</li>
<li><strong>Works: <code>writing-mode: sideways-lr</code> with <code>text-fit</code>.</strong> The fitted axis is the vertical one.</li>
<li><strong>Works: <code>createValueRange()</code> rectangles of a drawn input.</strong> One call per character. The check compares them with <code>measureText()</code> and reports the difference.</li>
<li><strong>Limit: the pieces are pictures.</strong> A character in flight is a copy of pixels. The text that can be selected and edited is the field's. This differs from <a href="https://html-in-canvas.page/particles/">/particles/</a>, where the hit box follows the letters.</li>
<li><strong>Not verified here:</strong> the on-screen keyboard on a phone (whether the field stays in view when the keyboard opens, and input from predictive text, which can replace a whole word in one event), and whether <code>createValueRange()</code> exists in Chrome 159 on Android. The status line under the picture says which method is in use.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/effects-from-css.md">findings/effects-from-css.md</a> in the repository.</p>
<h3><code>/tilt-card/</code> and <code>/text-labels/</code></h3>
<p>Built from the Chrome APIs plan (<code>/chrome-apis/</code>, demos 11 and 8). Chromium 157, software rendering, 2026-11-21.</p>
<p><code>/tilt-card/</code> draws three HTML cards through <code>fx</code> effects defined in the page (foil, hologram, lenticular). <code>lib/tilt-light.js</code> writes the lean to <code>--fx-x</code> and <code>--fx-y</code>. <code>/text-labels/</code> is one 2D canvas with no shader.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>A <code>deviceorientation</code> event drives the shader and the hit box through <code>--fx-x</code> and <code>--fx-y</code></td><td>works with a synthetic event</td><td>A 14 degree turn with a range of 28 gives <code>--fx-x</code> 0.50. The test browser has no sensor, so real events are not verified. <code>DeviceOrientationEvent.requestPermission()</code> and <code>navigator.vibrate</code> exist in the test browser, <code>navigator.haptics</code> does not.</td></tr>
<tr><td>A button on a card that leans in perspective is hit where it is drawn</td><td>works</td><td>The effect's <code>geometry</code> matrix goes to <code>updateElementGeometry()</code>. The button's box changed by 7.6 px and <code>elementFromPoint()</code> at its drawn middle returned the button.</td></tr>
<tr><td>The surface changes with the lean without a new upload of the element</td><td>works</td><td>26% of the pixels changed between lean -0.6 and 0.6 with the card held flat. Only uniforms changed.</td></tr>
<tr><td>A colour key: CSS paints a block magenta and the shader replaces it with a hologram</td><td>works</td><td>Middle of the block reads 255,0,255 in plain HTML and 1,64,49 under the shader. The key is a distance in colour, so a magenta-like colour elsewhere on the card would also be replaced.</td></tr>
<tr><td>Two faces of a badge interleaved in 6 px strips by <code>mask-image</code> whose stops depend on <code>--fx-x</code></td><td>works</td><td>Share of the second face 0.00 at lean -0.4, 0.50 at 0, 1.00 at 0.4. The shader adds only the lens ridges. Input goes to one face through <code>pointer-events</code>, switched by script when the lean crosses zero.</td></tr>
<tr><td>GLSL and WGSL versions of foil, hologram and lenticular give the same picture</td><td>works</td><td>Mean difference at most 0.10 of 255 per channel, WebGPU on a software adapter in the Chromium 157 shell.</td></tr>
<tr><td><code>text-fit: grow</code> on a canvas child, drawn at its <code>offsetWidth</code></td><td>works</td><td>12 px text is drawn 233 px wide in a 240 px box. <code>text-fit</code> only grows, so a label that must also shrink needs a small base font size.</td></tr>
<tr><td><code>text-box: trim-both cap alphabetic</code> on a canvas child</td><td>works</td><td>Untrimmed the element is 72 px tall and the ink starts at row 14. Trimmed it is 41 px tall and the ink starts at row 0. Descenders are outside the trimmed box and are cut by the element's picture, so the page uses capitals where it trims.</td></tr>
<tr><td><code>writing-mode: sideways-lr</code> with <code>text-fit</code></td><td>works</td><td>Ink 25 × 108 px in an element of 25 × 110 px. The fit is along the vertical axis.</td></tr>
<tr><td><code>input.createValueRange(i, i + 1).getBoundingClientRect()</code> for an input drawn in a canvas</td><td>works</td><td>One box per character, and the drawn ink is inside the boxes (143, 0 and 151 ink pixels for a letter, a space and a letter). The rect is in viewport coordinates at the drawn position, as in the plan's probe for Chromium 157.</td></tr>
<tr><td><code>measureText()</code> with the input's computed font against <code>createValueRange()</code></td><td>agrees</td><td>12 characters, left edges differ by at most 0.01 px. <code>lib/char-rects.js</code> uses it where <code>createValueRange()</code> is missing. It does not handle scrolled or right-to-left values.</td></tr>
<tr><td>Animating single characters of a live input</td><td>works</td><td>The canvas draws the input, copies the pixels of a character box and draws that copy scaled, flying or in 4 px pieces. A deleted character is taken from the copy of the previous frame. Letter colour is recovered from darkness, so it assumes dark text on a light field.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/text-labels/">Open Text measured by CSS for signs, labels and particles</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Inline text elements: sub, bdo, abbr, q, var and br</title>
<link>https://html-in-canvas.page/text-marks/</link>
<guid isPermaLink="true">https://html-in-canvas.page/text-marks/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>getClientRects</category>
<category>Range</category>
<category>drawElementImage</category>
<category>text</category>
<description>Subscripts that drop into their formulas, arrows that show the order of right-to-left text, an abbreviation whose title opens between two lines, large quotation marks behind a &lt;q&gt;, every &lt;var&gt; of one name outlined together, and a note that folds at its &lt;br&gt; elements.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/text-marks/"><img src="https://html-in-canvas.page/text-marks/social.jpg" width="1200" height="630" alt="The page &quot;Inline text elements: sub, bdo, abbr, q, var and br&quot;"></a></p>
<p><strong>Question:</strong> Inline elements aren't drawable by themselves. How much can a canvas do with sub, sup, bdo, abbr, q, var and br from their rectangles alone?</p>
<p><strong>Short answer:</strong> Enough for all six effects in Chromium 157. sub, sup, abbr, q and var have boxes, and a draw of the paragraph clipped to a box moves that element alone. Client rectangles follow the last draw and offset numbers do not. A br has a rectangle 0 px wide, so fold lines come from a Range over the text between breaks. The title of an abbr isn't in the picture.</p>
<p>
Six ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a> about elements that sit inside a line of text. None of them is a
<code>drawable</code> element: each is part of the picture of the paragraph around it. I wanted to know how much a canvas can do with
them from their rectangles alone, and what it can do for the one that has no width, <code>&lt;br&gt;</code>.
</p>
<h3>How it works</h3>
<ul>
<li><b>One drawable block per canvas.</b> The inline elements aren't <code>drawable</code>. A piece of the block is drawn by clipping a draw of the whole block to a box.</li>
<li><b>Two kinds of box.</b> <code>offsetLeft</code>, <code>offsetTop</code>, <code>offsetWidth</code> and <code>offsetHeight</code> are layout numbers and don't change with how the block is drawn. The demos that move pieces use them. <code>getClientRects()</code> of an element or a <code>Range</code> gives one rectangle per line, at the place where the block was last drawn. The demos that draw the block flat use those.</li>
<li><b>Frames.</b> A demo asks for frames only while something moves. The demos that read client rectangles draw their first frames twice, because the rectangles follow the draw before.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.</p>
<ul>
<li><b>Inline elements can be treated as pictures by clipping.</b> <code>sub</code>, <code>sup</code>, <code>abbr</code>, <code>q</code> and <code>var</code> have boxes inside a drawable block (a <code>sub</code> was 7 by 15 px in the check), and a draw of the block clipped to one box moves that element alone. Twelve subscripts and superscripts were dropped into place this way.</li>
<li><b>There are two kinds of box, and they behave differently.</b> Client rectangles follow the draw: the rectangle of a <code>var</code> moved by 60 and 30 px when its block was drawn at (60, 30). <code>offsetLeft</code> and <code>offsetTop</code> stayed at 35 and 3. A demo that moves pieces uses the offset numbers. A demo that draws the block flat can use either.</li>
<li><b>A block drawn in two pieces reports rectangles for the last piece only.</b> With the abbreviation's paragraph cut and its lower piece drawn 42 px down, every client rectangle in the paragraph was 42 px down, the ones above the cut too. The canvas finds the tapped abbreviation from the tap's position and the offset boxes.</li>
<li><b>A <code>br</code> has one client rectangle, 0 px wide. A <code>wbr</code> has none.</b> The fold lines come from a <code>Range</code> over the text between two breaks: tops 24 px apart for a 24 px line height.</li>
<li><b>A <code>q</code> has more rectangles than lines.</b> One for the opening mark the browser adds, one for each line of text and one for the closing mark: 3 for a one-line <code>q</code>, 5 for one that wraps once, 8 for the two in the demo.</li>
<li><b>Character rectangles show visual order.</b> In <code>&lt;bdo dir="rtl"&gt;</code> the last of six letters was 35.5 px to the left of the first. In a plain span it was 37.3 px to the right. The Hebrew run of 9 characters and the forced run of 20 were both reported right to left.</li>
<li><b>The <code>title</code> of an <code>abbr</code> isn't in the picture.</b> The block was 220 by 24 px with and without it. The demo draws the title from a real element in a gap it opens in the paragraph, and the abbreviations answer to touch and to Enter.</li>
<li><b>Not verified:</b> everything on a phone. Whether Android shows the <code>title</code> tooltip on a long press over a drawn abbreviation, text selection across the ornaments by touch, and Arabic or mixed-direction runs, which this page doesn't have.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/text-marks.md">findings/text-marks.md</a> in the repository.</p>
<p>Backlog group 28 in PLAN.md, ideas 28.5 to 28.10. Measured in headless Chromium 157 (C157) on 2026-11-21 at 412 px wide. The page's five live checks pass there, and <code>node tools/text-marks/check.mjs</code> drives the six demos by touch (20 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: inline elements are not drawable by themselves. How much can a canvas do with sub, sup, bdo, abbr, q, var and br from their rectangles alone?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>offsetWidth</code> and client rectangles of inline elements in a drawable block</td><td>sub 7 px, 1 rectangle (7 by 15); sup the same; abbr 22 px, 1; var 7 px, 1</td><td>They have boxes, so a clipped draw of the block can stand in for a picture of the element.</td></tr>
<tr><td><code>q</code></td><td>3 rectangles for one line (7 by 17, 8 by 17, 7 by 17), 5 when it wraps once</td><td>The opening and closing marks the browser adds have rectangles of their own.</td></tr>
<tr><td><code>br</code></td><td>0 px wide, 1 rectangle (0 by 17)</td><td>A place, not a box.</td></tr>
<tr><td><code>wbr</code></td><td>0 px wide, 0 rectangles</td><td></td></tr>
<tr><td>The block drawn at (60, 30) instead of (0, 0)</td><td>client rectangle of a <code>var</code> moved by 60 and 30 px; <code>offsetLeft</code> 35 and <code>offsetTop</code> 3 in both</td><td>Client rectangles follow the draw. Offset numbers are layout.</td></tr>
<tr><td>A block drawn as two pieces, the lower one 42 px down (<code>/text-marks/</code> gloss demo, tool script)</td><td>every client rectangle in the block is 42 px down, including those above the cut</td><td>The rectangles follow the last <code>drawElementImage()</code> call for the element. The demo does its own hit test from offset boxes.</td></tr>
<tr><td>Twelve <code>sub</code> and <code>sup</code> pieces drawn on their way to holes in the block</td><td>all 12 in place after 3.5 s, no frames afterwards, the link in the block still answers</td><td>Subscripts that settle (28.5).</td></tr>
<tr><td>One <code>Range</code> per character in <code>bdo dir="rtl"</code>, a Hebrew <code>bdi</code> and a plain span</td><td>bdo: last of six letters 35.5 px left of the first; span: 37.3 px right. Demo: 13 left to right, 9 and 20 right to left</td><td>Bidirectional text explained (28.6).</td></tr>
<tr><td>A block with and without <code>title</code> on its <code>abbr</code></td><td>220 by 24 px both times</td><td>The tooltip is not in the picture. Abbreviations expanded in place (28.7) draws the title from a real element in a gap.</td></tr>
<tr><td>Marks, bands and a wave drawn from the rectangles of <code>q</code> and <code>cite</code>, under the text</td><td>8 rectangles for the demo's two <code>q</code> elements</td><td>Quotation marks as ornaments (28.8).</td></tr>
<tr><td>A <code>click</code> on a <code>var</code> in a block drawn flat</td><td>every <code>var</code> of that name outlined: 5 for <code>sum</code>, 4 for <code>n</code></td><td>Variables that light up together (28.9). Ordinary events, because a flat draw has a hit region that fits.</td></tr>
<tr><td>A <code>Range</code> over each text node between two <code>br</code> elements</td><td>line tops 24 px apart for a 24 px line height; 6 strips from 5 <code>br</code> in the demo</td><td>Line breaks as cut lines (28.10). The strips are squashed, sheared and shaded with <code>source-atop</code>.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops the six canvases and shows the text as plain HTML (6 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first version of the fold demo printed "A br has 1 client rectangles". The page's text had said a <code>br</code> has none. It has one, 0 px wide.</li>
<li>The large quotation marks were first placed with <code>textAlign</code> right and left of the <code>q</code> rectangles and covered the words before and after. They are now centred on the first and last rectangle, which are the browser's own marks.</li>
<li>The tool script taps an element at its client rectangle. For an abbreviation above the cut that rectangle is 42 px too low while the gloss is open, so the script subtracts the gap for that one tap.</li>
<li>Client rectangles are only right after a paint, so the demos that use them draw their first frames twice.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: the six demos by touch.</li>
<li>Whether Android shows the <code>title</code> tooltip on a long press over a drawn <code>abbr</code>.</li>
<li>Text selection by touch across the ornaments and the outlines.</li>
<li>Arabic, and a run that mixes directions inside one <code>Range</code>. The page has one Hebrew run and one forced run.</li>
<li>A subscript whose box overlaps another glyph. The clip would take a part of that glyph with it.</li></ul>
<p><a href="https://html-in-canvas.page/text-marks/">Open Inline text elements: sub, bdo, abbr, q, var and br</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Annotated article</title>
<link>https://html-in-canvas.page/text-notes/</link>
<guid isPermaLink="true">https://html-in-canvas.page/text-notes/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>ruby</category>
<category>blockquote</category>
<category>h2</category>
<category>sup</category>
<category>del</category>
<category>ctx.filter</category>
<category>drawElementImage</category>
<description>Six text effects on one article, all cut from the article's own picture: ruby that shows near the pointer, the quote drawn again large behind the column, a selection that glows, a heading whose glyphs fly in, footnotes that slide out beside the line, and strike-through drawn by a pen.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/text-notes/"><img src="https://html-in-canvas.page/text-notes/social.jpg" width="1200" height="630" alt="The page &quot;Annotated article&quot;"></a></p>
<p><strong>Question:</strong> Can one 2D canvas make six text effects (ruby, pull quote, selection glow, kinetic heading, footnotes, strike-through) from one article's picture, with no change to the article's markup?</p>
<p><strong>Short answer:</strong> Yes. Clip paths and source rectangles of one <code>drawElementImage()</code> picture give all six. <code>ctx.filter</code> applies to the picture, so a colour matrix can pick out the selection colour with no readback.</p>
<p>
The article below is one element drawn by a 2D canvas. The canvas draws parts of the article's picture a second time, or leaves parts out, to make six effects.
The heading's glyphs fly in. Ruby annotations show only near the pointer or the last tap. The quote is drawn again behind the text, large and faint, and moves as the page scrolls.
Selected text glows. A tap on a footnote number slides the note out beside the line. Struck and inserted words get a pen stroke, and with the checkbox on a tap on a word strikes it.
</p>
<h3>How it works</h3>
<p>The article is a child of a <code>&lt;canvas content="drawable"&gt;</code>. On every <code>paint</code> event the page reads the client rectangles it needs and then draws the layers in this order:
background, pull quote, glow, the article, ruby, heading glyphs, pen strokes, the open footnote. The page asks for frames only while something is moving.</p>
<dl>
<dt>Ruby near the pointer</dt>
<dd>The article is drawn through a clip path that has a hole for the box of every <code>&lt;rt&gt;</code>, so no annotation is drawn. For each <code>rt</code> within 130 px of the pointer the page draws
that box of the article again with <code>drawElementImage()</code> and a source rectangle, at an alpha that falls with distance. The <code>rt</code> elements stay in the document.</dd>
<dt>Pull quote behind the column</dt>
<dd>The rectangle of the <code>&lt;blockquote&gt;</code> is drawn before the article, scaled up to about three times its size at 10% alpha and turned by 4 degrees. Its horizontal position follows the scroll position of the page.</dd>
<dt>Selection that glows</dt>
<dd>The browser paints the selection into the article's picture. With "Colour key filter" the page draws the article once more through an SVG filter set as <code>ctx.filter</code>: a colour matrix keeps pixels near the selection colour, a blur spreads them,
and the result is added to the canvas. The filter knows nothing about the selection, so the <code>&lt;mark&gt;</code> with the same colour glows too. With "Range rectangles" the page blurs filled rectangles from <code>Range.getClientRects()</code>.</dd>
<dt>Kinetic heading</dt>
<dd>While the heading animates, its box is clipped out of the article and each glyph box is drawn as its own piece, with a translation, a rotation and a scale that all end at the glyph's place in the layout.
The <code>&lt;h2&gt;</code> isn't changed. It keeps its text, its place in the outline and its hit region.</dd>
<dt>Footnotes that slide out</dt>
<dd>Each note is an <code>&lt;aside&gt;</code> that is a child of the canvas and isn't drawn until its link is tapped. The click on the link is cancelled, and the canvas draws the note under the line (in the margin beside the line on a wide screen),
moving in from the right edge. A drawn note has a hit region, so the link inside it works. Without the API the notes are at the foot of the article and the links jump to them.</dd>
<dt>Strike-through drawn by hand</dt>
<dd><code>s</code>, <code>del</code> and <code>ins</code> have <code>text-decoration: none</code> inside the canvas. The canvas draws a pen stroke along each of their line boxes: two passes through struck text, an underline and a caret for inserted text.
A new element is drawn in over time. "Tap a word to strike it" wraps the word under the tap in a <code>&lt;del&gt;</code>. A second tap removes it.</dd>
</dl>
<h3>Findings</h3>
<ul>
<li>A 2D canvas <code>filter</code> applies to <code>drawElementImage()</code>, both a <code>blur()</code> function and a <code>url()</code> reference to an SVG filter. A colour matrix can therefore select pixels of the element's picture by colour with no readback.</li>
<li>The selection highlight is in the element's picture, and a change of selection fires <code>paint</code> with no call from the page.</li>
<li>A source rectangle of an element drawn at five times its size is drawn from the recorded picture at that size. The glyph edges are as sharp as at the original size, unlike a scaled copy of the canvas pixels.</li>
<li>An <code>&lt;rt&gt;</code> has its own client rectangle. A clip path with a hole for that rectangle removes the annotation and leaves the base text, because ruby text is laid out in its own box above the line.</li>
<li>A drawable child of the canvas has a hit region only in a frame that draws it, and where two children overlap the one drawn last takes the click. A footnote that isn't drawn doesn't take clicks, so a closed note needs no extra step.</li>
<li><code>caretPositionFromPoint()</code> on a drawn element returns the text node and offset under the point, at the drawn position.</li>
<li>A draw with a source rectangle moves the element's hit region to the piece and gives it the size of the piece. <code>updateElementGeometry()</code> afterwards moves the region back but keeps the size of the piece: a 120 px heading answered at 6 of 36 points.
A whole draw inside an empty clip restores the whole region. The page ends every frame with that draw. The rectangles from <code>getClientRects()</code> move with the piece too, so the page reads them all before the first such draw.</li>
<li>After a mouse click inside the article in the test browser, a selection set from script was in <code>getSelection()</code> but not in the picture until a control outside the canvas was clicked. Cause not found.</li>
<li>Not verified: Chrome 159 for Android. Long-press selection inside the article, the cost of the filter on a phone GPU, and whether a tap near a ruby word is a usable replacement for hover. The status line under the demo prints the time of the last paint.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/text-notes.md">findings/text-notes.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell, 157.0.8103.78), 2026-11-21, at 412 px wide with device scale factors 2 and 2.625, and at 1100 px wide with scale 1. Not yet run on the test phone (Chrome 159 for Android).</p>
<p>Ideas built, all from <code>public/elements/ideas.js</code> (rank 2, text), PLAN.md backlog group 14: "Ruby that appears near the pointer", "Pull quote behind the column", "Selection that glows", "Kinetic heading", "Footnotes that slide out", "Strike-through drawn by hand". One page, one 2D canvas, one article element, and three footnote elements that are separate children of the canvas.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Does a 2D canvas <code>filter</code> apply to <code>drawElementImage()</code>?</td><td>measured: yes, for <code>blur()</code> and for <code>url()</code> to an SVG filter</td><td>Through <code>blur(3px)</code> a paragraph had 5,319 soft pixels (alpha 40 to 215) against 987 plain (scale 2.625). Through an SVG filter with a colour matrix and a blur, 13,161 pixels came out around the selected words and 0 over plain text 100 px away.</td></tr>
<tr><td>Can the selection be picked out of the picture by colour, with no readback?</td><td>measured: yes</td><td><code>feColorMatrix</code> with alpha = 1.5 G + 1.5 B - 3 R - 1.2 keeps <code>#19e3ff</code> and rejects the text colours used on the page. The filter also lights a <code>&lt;mark&gt;</code> of the same colour, which a route based on <code>Range.getClientRects()</code> cannot see.</td></tr>
<tr><td>Is a selection set from script in the picture, and does it fire <code>paint</code>?</td><td>measured: yes</td><td>1 paint event after <code>setBaseAndExtent()</code>, 9,824 pixels of the <code>::selection</code> colour in the Range box.</td></tr>
<tr><td>Is a source rectangle drawn larger taken from the recorded picture or from pixels?</td><td>measured: from the recorded picture</td><td>A 12 px word drawn at five times its size had 0.07 soft edge pixels for each solid pixel. The same word enlarged with <code>drawImage()</code> of the canvas pixels had 0.77 (scale 2.625; 0.22 against 4.45 at scale 1).</td></tr>
<tr><td>Does an <code>&lt;rt&gt;</code> have its own client rectangle, and does a clip hole remove only the annotation?</td><td>measured: yes</td><td>rt box 53 by 13 px. 557 gold pixels in it without the hole, 0 with it, base text unchanged (942 pixels).</td></tr>
<tr><td>Do pieces for each glyph box rebuild a heading exactly?</td><td>measured: yes, within 0.1%</td><td>16 boxes for 16 characters, 7,972 ink pixels from one draw, 7,969 from 16 pieces padded by 0.5 px.</td></tr>
<tr><td>Where is an element's hit region after a draw with a source rectangle?</td><td>measured: at the piece, with the size of the piece</td><td>A 120 px heading with one 17 px glyph drawn at 150, 60: 0 of 36 points in the layout box hit the heading, the piece did.</td></tr>
<tr><td>Does <code>updateElementGeometry()</code> restore the region after that?</td><td>measured: the place yes, the size no</td><td>6 of 36 points hit. The region is at 0, 0 with the size of the glyph.</td></tr>
<tr><td>Does a whole draw in an empty clip restore it?</td><td>measured: yes</td><td>36 of 36 points. The page ends each frame with it (<code>settle()</code>).</td></tr>
<tr><td>Is a drawable child that is not drawn in a frame hit tested?</td><td>measured: no</td><td>A note drawn at 160, 60 is returned by <code>elementFromPoint()</code>. In the next paint that does not draw it, the point returns the paragraph under it.</td></tr>
<tr><td>Which of two overlapping drawn children takes a click?</td><td>measured: the one drawn last</td><td>With the article's empty-clip draw after the note, a point on the open note returned an element of the article. With the note drawn last it returns the note. DOM order did not decide it.</td></tr>
<tr><td>Does <code>caretPositionFromPoint()</code> work on a drawn element?</td><td>measured: yes</td><td>A paragraph drawn at 20, 10: offset 9 in its text node for the middle of a word at offsets 6 to 12. The page uses it to find the word under a tap.</td></tr>
<tr><td>Does wrapping a word in <code>&lt;del&gt;</code> fire <code>paint</code>?</td><td>measured: yes</td><td>1 paint event, 3 line boxes for a <code>del</code> over three lines.</td></tr>
<tr><td>How are the canvas's children laid out with <code>layoutsubtree</code>?</td><td>measured: each at 0, 0</td><td>The three notes all have <code>offsetTop</code> 0. They do not stack as blocks under the article.</td></tr>
<tr><td>Cost of a paint</td><td>measured: 0.3 to 1.2 ms of script</td><td>Software rendering. The filter runs on the compositor side and is not in this number.</td></tr>
<tr><td>Jank guard</td><td>measured: pass</td><td><code>cls 0 scroll 0 focus 0</code>, 5.8 MB and 1.46 megapixels of canvas at 412 px and scale 2.625, 0 readbacks, 0 open snapshots.</td></tr>
<tr><td>Touch (Playwright <code>touchscreen.tap</code>, 412 px)</td><td>measured: works</td><td>A tap near a ruby word shows its annotation. A tap on a footnote number opens the note and a tap elsewhere closes it. With the checkbox on, a tap on a word wraps it in <code>&lt;del&gt;</code> and a second tap removes it.</td></tr>
<tr><td>Without the API (<code>--disable-blink-features=CanvasDrawElement</code>)</td><td>measured: plain HTML</td><td>The article, then the three notes. Ruby is shown, <code>s</code>, <code>del</code> and <code>ins</code> have the browser's lines, and the footnote links jump to the notes.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li><code>home()</code> in <code>lib/text-canvas.js</code> uses <code>updateElementGeometry()</code>. After a draw with a source rectangle that leaves the element with a hit region the size of the piece (see the table). <code>/text-notes/</code> does not use it and ends the frame with a whole draw in an empty clip. The five pages that use <code>home()</code> (<code>/mark-pen/</code>, <code>/keycaps/</code>, <code>/split-flap/</code>, <code>/flip-clock/</code>, <code>/typed-code/</code>) should be checked for clicks that miss after a piece draw. Not changed here: the file belongs to another strand.</li>
<li><code>getClientRects()</code> follows the last draw, so one frame must read every rectangle before its first piece draw. The page does this in <code>readBoxes()</code>.</li>
<li><code>.ann ::selection</code> does not match text that is a direct child of <code>.ann</code>. A check fixture whose paragraph had the class itself was painted with the default selection colour, and the colour count was 0. The rule is <code>.ann::selection, .ann ::selection</code>.</li>
<li><code>ctx.filter</code> lengths are in canvas pixels and are not scaled by the context's transform. The blur radius is multiplied by the pixel ratio (<code>stdDeviation</code> is set from script for the SVG filter).</li>
<li>The element drawn last takes the click. The article's empty-clip draw has to come before the open note is drawn.</li>
<li>A global <code>.note</code> rule exists in <code>shared/style.css</code>. The footnotes use the class <code>side-note</code>.</li>
<li>After a real mouse click inside the article in the test browser, a selection set from script (the "Select the quote" button called with <code>element.click()</code>) was in <code>getSelection()</code> and fired <code>paint</code>, but was not in the picture. A real click on the button, which moves focus to it, showed it. Cause not found. A selection set from script before any click in the canvas is painted.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 for Android, all of it. To verify: open <code>/text-notes/</code> on the phone. The heading should fly in, the pen strokes should draw after it, a tap near a Japanese word should show its reading, and a tap on a footnote number should slide the note in from the right.</li>
<li>Long-press selection inside the article and its glow. The headless browser selects nothing on a long press. To verify: long-press a word, or press "Select the quote".</li>
<li>The cost of the SVG filter on a phone GPU. The filter is applied to the whole article on every paint while a selection exists, including paints caused by scrolling. To verify: select the quote, scroll, and compare with Glow set to "Range rectangles" or "Off".</li>
<li>Whether a tap is a usable replacement for hover for the ruby effect. Ruby "All" shows every annotation.</li>
<li>Screen reader output for <code>rt</code>, the notes (<code>role="note"</code>, <code>aria-expanded</code> on the links) and <code>del</code>/<code>ins</code>.</li>
<li>CJK font on the phone. The test browser used IPAGothic.</li></ul>
<h3>Open ideas</h3>
<ul><li>Cache the glow layer in a second plain canvas with <code>drawImage()</code> and reuse it until the selection changes, so the filter does not run on scroll.</li>
<li>Open the gap for a footnote inside the text: draw the article in two pieces, above and below the line, and the note between them. This needs a hit region for each piece, which one element cannot have.</li>
<li>Ruby driven by reading level: hide the annotation of a word after the reader has revealed it three times.</li>
<li>A kinetic heading whose glyphs scatter when the heading scrolls off the stage and gather when it returns.</li>
<li>Erase a pen stroke by rubbing over it, which removes the <code>&lt;del&gt;</code>.</li></ul>
<p><a href="https://html-in-canvas.page/text-notes/">Open Annotated article</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Tilt the phone to light a card</title>
<link>https://html-in-canvas.page/tilt-card/</link>
<guid isPermaLink="true">https://html-in-canvas.page/tilt-card/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>deviceorientation</category>
<category>updateElementGeometry</category>
<category>mask-image</category>
<category>@property</category>
<description>A payment card, a ticket and a badge made of HTML, drawn through foil, hologram and lenticular shaders. The phone's tilt leans them and moves the light. Their buttons work while they lean.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/tilt-card/"><img src="https://html-in-canvas.page/tilt-card/social.jpg" width="1200" height="630" alt="The page &quot;Tilt the phone to light a card&quot;"></a></p>
<p><strong>Question:</strong> Can the phone's orientation sensor drive the shader and the hit box of live DOM, through two CSS custom properties?</p>
<p><strong>Short answer:</strong> The path from a <code>deviceorientation</code> event to the picture and to hit testing works with synthetic events. The sensor itself needs a phone.</p>
<p>
Three cards made of HTML, drawn through foil, hologram and lenticular shaders. Press "Use the phone's tilt" and tilt the phone: the
cards lean and their surfaces change with the angle. Without a sensor, move the pointer or drag a finger across the panel. The buttons
on the cards work while they lean. The third card has two faces and shows one or the other by angle.
</p>
<h3>How it works</h3>
<ul>
<li><code>tiltLight()</code> writes the lean to two custom properties on the panel. The <a href="https://html-in-canvas.page/shader-css/">fx library</a> passes them to each card's shader as <code>u_xy</code> and to the card's <code>geometry</code> function, which returns a perspective matrix.</li>
<li>The picture of a card is uploaded once. While the phone tilts only the two numbers change, so the foil and hologram cards cost one draw per frame and no upload.</li>
<li>The shader can't know which part of a card is the hologram. CSS paints that part magenta, and the shader replaces pixels close to magenta.</li>
<li>The lenticular card is the exception to "no upload". Its two faces are interleaved by CSS masks whose strip width is computed from <code>--fx-x</code>, so its picture changes with the lean and is uploaded again.</li>
<li>When the lean crosses zero the page sets <code>data-face</code> on the badge, which moves <code>pointer-events</code> to the face that shows more, and calls <code>navigator.vibrate(8)</code>.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software rendering and no orientation sensor. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: buttons on a leaning card.</strong> The perspective matrix goes to <code>updateElementGeometry()</code>, and <code>elementFromPoint()</code> finds a button at its drawn position at full lean.</li>
<li><strong>Works: a colour as a mask.</strong> A magenta block in the DOM is replaced by the shader. The edge of the block is one soft pixel. A card that falls back to plain HTML shows the magenta block.</li>
<li><strong>Works: lenticular faces in CSS.</strong> <code>mask-image</code> with a strip width from <code>calc()</code> of a registered property is applied in the picture, and the picture follows the property.</li>
<li><strong>Limit: one input face at a time.</strong> Both faces of the badge are in the same place. Which one takes a press is decided by script at the zero crossing, not by what each strip shows.</li>
<li><strong>Not verified here:</strong> everything about the sensor. The test browser has none, so the check above sends a synthetic <code>deviceorientation</code> event. Open on the phone: the event rate, the latency, whether Chrome on Android asks for permission, and whether <code>navigator.vibrate()</code> gives a tick at the flip. The web haptics API isn't in the test browser and isn't used.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/effects-from-css.md">findings/effects-from-css.md</a> in the repository.</p>
<h3><code>/tilt-card/</code> and <code>/text-labels/</code></h3>
<p>Built from the Chrome APIs plan (<code>/chrome-apis/</code>, demos 11 and 8). Chromium 157, software rendering, 2026-11-21.</p>
<p><code>/tilt-card/</code> draws three HTML cards through <code>fx</code> effects defined in the page (foil, hologram, lenticular). <code>lib/tilt-light.js</code> writes the lean to <code>--fx-x</code> and <code>--fx-y</code>. <code>/text-labels/</code> is one 2D canvas with no shader.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>A <code>deviceorientation</code> event drives the shader and the hit box through <code>--fx-x</code> and <code>--fx-y</code></td><td>works with a synthetic event</td><td>A 14 degree turn with a range of 28 gives <code>--fx-x</code> 0.50. The test browser has no sensor, so real events are not verified. <code>DeviceOrientationEvent.requestPermission()</code> and <code>navigator.vibrate</code> exist in the test browser, <code>navigator.haptics</code> does not.</td></tr>
<tr><td>A button on a card that leans in perspective is hit where it is drawn</td><td>works</td><td>The effect's <code>geometry</code> matrix goes to <code>updateElementGeometry()</code>. The button's box changed by 7.6 px and <code>elementFromPoint()</code> at its drawn middle returned the button.</td></tr>
<tr><td>The surface changes with the lean without a new upload of the element</td><td>works</td><td>26% of the pixels changed between lean -0.6 and 0.6 with the card held flat. Only uniforms changed.</td></tr>
<tr><td>A colour key: CSS paints a block magenta and the shader replaces it with a hologram</td><td>works</td><td>Middle of the block reads 255,0,255 in plain HTML and 1,64,49 under the shader. The key is a distance in colour, so a magenta-like colour elsewhere on the card would also be replaced.</td></tr>
<tr><td>Two faces of a badge interleaved in 6 px strips by <code>mask-image</code> whose stops depend on <code>--fx-x</code></td><td>works</td><td>Share of the second face 0.00 at lean -0.4, 0.50 at 0, 1.00 at 0.4. The shader adds only the lens ridges. Input goes to one face through <code>pointer-events</code>, switched by script when the lean crosses zero.</td></tr>
<tr><td>GLSL and WGSL versions of foil, hologram and lenticular give the same picture</td><td>works</td><td>Mean difference at most 0.10 of 255 per channel, WebGPU on a software adapter in the Chromium 157 shell.</td></tr>
<tr><td><code>text-fit: grow</code> on a canvas child, drawn at its <code>offsetWidth</code></td><td>works</td><td>12 px text is drawn 233 px wide in a 240 px box. <code>text-fit</code> only grows, so a label that must also shrink needs a small base font size.</td></tr>
<tr><td><code>text-box: trim-both cap alphabetic</code> on a canvas child</td><td>works</td><td>Untrimmed the element is 72 px tall and the ink starts at row 14. Trimmed it is 41 px tall and the ink starts at row 0. Descenders are outside the trimmed box and are cut by the element's picture, so the page uses capitals where it trims.</td></tr>
<tr><td><code>writing-mode: sideways-lr</code> with <code>text-fit</code></td><td>works</td><td>Ink 25 × 108 px in an element of 25 × 110 px. The fit is along the vertical axis.</td></tr>
<tr><td><code>input.createValueRange(i, i + 1).getBoundingClientRect()</code> for an input drawn in a canvas</td><td>works</td><td>One box per character, and the drawn ink is inside the boxes (143, 0 and 151 ink pixels for a letter, a space and a letter). The rect is in viewport coordinates at the drawn position, as in the plan's probe for Chromium 157.</td></tr>
<tr><td><code>measureText()</code> with the input's computed font against <code>createValueRange()</code></td><td>agrees</td><td>12 characters, left edges differ by at most 0.01 px. <code>lib/char-rects.js</code> uses it where <code>createValueRange()</code> is missing. It does not handle scrolled or right-to-left values.</td></tr>
<tr><td>Animating single characters of a live input</td><td>works</td><td>The canvas draws the input, copies the pixels of a character box and draws that copy scaled, flying or in 4 px pieces. A deleted character is taken from the copy of the previous frame. Letter colour is recovered from darkness, so it assumes dark text on a light field.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/tilt-card/">Open Tilt the phone to light a card</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Timed comments that cross the video</title>
<link>https://html-in-canvas.page/timed-comments/</link>
<guid isPermaLink="true">https://html-in-canvas.page/timed-comments/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>TextTrack</category>
<category>VTTCue</category>
<category>requestVideoFrameCallback</category>
<category>drawElementImage</category>
<description>Comments are cues in a metadata text track. Each active one is a drawable element that the canvas draws at a position worked out from the media time of the frame, so it crosses the picture in step with the video. Tap one to stop it and open its Like button. The text can invert the frame or ride a wave.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/timed-comments/"><img src="https://html-in-canvas.page/timed-comments/social.jpg" width="1200" height="630" alt="The page &quot;Timed comments that cross the video&quot;"></a></p>
<p><strong>Question:</strong> Can comments cross a video as real elements that take taps where they are drawn, placed for the exact frame in the picture?</p>
<p><strong>Short answer:</strong> Yes. In every paint of a playing fixture the comment's position was the one for the frame number read from the same picture, and a frame-by-frame export moves each comment by the same step in every frame.</p>
<p>
Each comment below is an HTML element that the canvas draws over the video, at a position worked out from the time of the video frame.
Press Play. Tap a comment to stop it and open its Like button. Write one of your own and it's added at the current time.
</p>
<h3>How it works</h3>
<ul>
<li>The comments live in a text track of kind <code>metadata</code>. A cue runs from the comment's time for 4 seconds, the time a comment takes to cross. The browser keeps <code>activeCues</code> current, so the page holds elements only for the comments on screen.</li>
<li>Every comment is its own <code>drawable</code> child of the canvas. The paint handler computes <code>x = W − (t − start) ÷ 4 × (W + width)</code> from the media time <code>t</code> that <code>requestVideoFrameCallback()</code> reported for the frame, and draws the element there.</li>
<li><code>drawElementImage()</code> sets the element's hit-test region to where it was drawn, including the rotation in the wave mode. A tap on a moving comment is an ordinary <code>click</code> on its button.</li>
<li>The inverting mode sets <code>globalCompositeOperation = 'difference'</code> for the draw call. White text then shows the inverse of the frame under it.</li>
<li>A Like is written back into the cue's JSON text, so the count is still there when the video loops and the element is built again.</li>
<li>The export pauses the video, seeks to each frame time and asks the cue library for the cues at that time by comparing times, because <code>activeCues</code> is updated only after the seek has finished.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless with software video decoding, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: a metadata track as the store.</strong> <code>addTextTrack('metadata')</code> starts in the <code>hidden</code> mode, and cues added by script enter <code>activeCues</code> like cues from a file.</li>
<li><strong>Works: elements added and removed while the video plays.</strong> A new <code>drawable</code> child can't be drawn until the browser has recorded it once. The first <code>drawElementImage()</code> call throws, so the paint handler skips the element and asks for another paint.</li>
<li><strong>Works: the position matches the frame.</strong> The third check plays a fixture and, in each paint, reads the frame number from the stripes in the picture. It reports how many paints drew the comment for that same frame.</li>
<li><strong>Works: taps on moving and rotated comments.</strong> <code>elementFromPoint()</code> finds the comment's button at the drawn place, and no longer finds it there after the comment has moved on.</li>
<li><strong>Works: the <code>difference</code> blend mode on an element.</strong> The composite operation applies to <code>drawElementImage()</code> as it does to <code>drawImage()</code>.</li>
<li><strong>Works: frame-exact export.</strong> In an exported file the comment moves the same number of pixels in every frame.</li>
<li><strong>Limit: a comment that starts in the last 4 seconds is cut off when the clip loops.</strong> Its cue can't run past the end of the video.</li>
<li><strong>Not verified:</strong> the frame match with a hardware decoder on Android, the cost of 30 or more comments on a phone, and tapping a moving comment with a finger. The third check and the line under the player report the first two on the device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/timed-comments.md">findings/timed-comments.md</a> in the repository.</p>
<p>Measured in Chromium 157 headless (C157) with software video decoding, 2026-11-21. The clip is <code>public/media/clip.webm</code>, which carries its frame number as stripes in the picture.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>video.addTextTrack('metadata')</code> as the store for comments</td><td>works</td><td>The track starts in the <code>hidden</code> mode. Each comment is a <code>VTTCue</code> from its time for 4 s with JSON as its text. <code>activeCues</code> held all three test cues at 2.5 s and two at 5.2 s.</td></tr>
<tr><td>One <code>drawable</code> child of the canvas per active cue, added and removed while the video plays</td><td>works</td><td><code>lib/cue-layer.js</code> with a <code>render</code> function. A child added since the last paint cannot be drawn yet: <code>drawElementImage()</code> throws, the handler skips it and asks for another paint.</td></tr>
<tr><td>Position from the frame's media time</td><td>within 1.5 px of the formula</td><td><code>x = W − (t − start) ÷ 4 × (W + width)</code>. <code>getBoundingClientRect()</code> of each comment matched it at 3.0 s.</td></tr>
<tr><td>Is the comment placed for the frame that is in the picture?</td><td>45 of 45 paints</td><td>During 1.5 s of playback the paint handler read the frame number from the stripes it had just drawn and compared it with the <code>mediaTime</code> from <code>requestVideoFrameCallback()</code> that the comments were placed for.</td></tr>
<tr><td>Hit test on a rotated, moving comment</td><td>works</td><td>In the wave mode at −0.14 rad, <code>elementFromPoint()</code> at the drawn centre returned the comment's button. After a seek that moved the comment 100 px, the same point returned the video. The stale hit-test answer seen with <code>updateElementGeometry()</code> did not appear with 2D <code>drawElementImage()</code>.</td></tr>
<tr><td>Click on a comment, then on the Like button of the opened card</td><td>works</td><td>The click paused the video and opened the card. The Like button was hit at its drawn place. The count is written into the cue's <code>text</code>, so it is still there after the clip loops.</td></tr>
<tr><td>A real touch tap on a comment (test driver, phone emulation)</td><td>works</td><td>The card opened with Like, Go to and Close.</td></tr>
<tr><td><code>globalCompositeOperation = 'difference'</code> for one <code>drawElementImage()</code> call</td><td>works</td><td>700 of 900 changed pixels were the inverse of the frame under white text.</td></tr>
<tr><td>Frame-by-frame export with <code>exportFrames()</code></td><td>the same step in every frame</td><td>12 frames. The comment moved 3.23 px per frame with a largest error of 0.06 px. The cues for each frame time are chosen by comparing times, because <code>activeCues</code> updates only after the seek.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The status line was written before the paint and showed the last paint's count of drawn comments. It is now written from a <code>paint</code> listener registered after the drawing one.</li>
<li>With <code>layoutsubtree</code>, the comment elements need <code>position: absolute</code> so that twelve of them do not change the layout of the video and the bar.</li>
<li>A comment that starts in the last 4 s of the clip is cut off at the loop, because its cue cannot run past the end of the video.</li></ul>
<h3>Not verified</h3>
<ul><li>The frame match with a hardware decoder on Android. The third live check reports it on the device.</li>
<li>Tapping a moving comment with a finger, and the cost of 30 or more comments on a phone. The line under the player shows how many are drawn in each paint.</li>
<li>The third check reads one row of a 320×180 fixture per frame for 1.5 s. It reads a <code>drawImage()</code> copy on an <code>OffscreenCanvas</code>, not the drawable canvas, and no drawable canvas on the page is made with <code>willReadFrequently</code> (that option loses every 2D context on an Android phone). It is not used by the visible player.</li></ul>
<h3>Open ideas</h3>
<ul><li>Comments that pass behind a subject, with a segmentation mask of the frame as the clip.</li>
<li>A density strip under the frame drawn from the same cues, where a tap seeks.</li>
<li>Comments from another tab over <code>BroadcastChannel</code>, added as cues at the current time.</li></ul>
<p><a href="https://html-in-canvas.page/timed-comments/">Open Timed comments that cross the video</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>An accessibility tree for a Dear ImGui app</title>
<link>https://html-in-canvas.page/toolkit-aria/</link>
<guid isPermaLink="true">https://html-in-canvas.page/toolkit-aria/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>updateElementGeometry</category>
<category>accessibility</category>
<description>Dear ImGui draws its own button, checkbox, slider and text field. Each one gets a real element inside the canvas that is never drawn and is placed with updateElementGeometry(), so the browser has a role, a name, a state and a box for it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/toolkit-aria/"><img src="https://html-in-canvas.page/toolkit-aria/social.jpg" width="1200" height="630" alt="The page &quot;An accessibility tree for a Dear ImGui app&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas toolkit give each widget it draws a real DOM node that is never drawn, so that the accessibility tree, hit testing, Tab order and focus describe the toolkit's own widgets?</p>
<p><strong>Short answer:</strong> Yes in Chromium 157. The accessibility tree has the role, name, state and the bounds ImGui drew. A screen reader wasn't run.</p>
<p>
Dear ImGui draws its button, checkbox, slider and text field as pixels, so a browser sees one canvas and nothing inside it.
Here every ImGui widget also has a real element inside the canvas: a <code>&lt;button&gt;</code>, an <code>&lt;input type="checkbox"&gt;</code>,
an <code>&lt;input type="range"&gt;</code>, an <code>&lt;input type="text"&gt;</code>. The elements are never drawn.
<code>updateElementGeometry()</code> puts each one at the rectangle ImGui reports for its widget.
Use the app by touch or mouse, or press Tab and use Space, Enter and the arrow keys. Tap the text field to type.
Turn on the outlines to see where the browser believes each element is.
</p>
<h3>How it works</h3>
<ul>
<li><strong>ImGui to DOM.</strong> The app calls <code>A11y(role, label, state)</code> after each widget. It reads the rectangle and id of the last item from ImGui (<code>g.LastItemData</code>) and the clip rectangle of the window, and calls the page. The page keeps one element per ImGui id, writes <code>checked</code>, <code>value</code>, <code>aria-valuetext</code>, <code>aria-expanded</code> or the status text when they changed, sets the element's CSS size to the widget's size, and calls <code>updateElementGeometry(el, { canvasTransform, canvasClip })</code> when the rectangle changed.</li>
<li><strong>DOM to ImGui.</strong> A <code>click</code> whose <code>pointerType</code> is empty (Enter, Space, <code>click()</code>, assistive technology) presses the ImGui button through ImGui's keyboard activation ids, or sets the checkbox. An <code>input</code> event on the range node sets the slider. An <code>input</code> event on the text node copies its value into the <code>InputText</code> buffer. A <code>focus</code> event makes the widget ImGui's focused item, and ImGui draws its focus ring when the node matches <code>:focus-visible</code>.</li>
<li><strong>Pointer.</strong> A press lands on a node, because the browser hit tests the nodes. A capture listener on the canvas sends every pointer event to ImGui, so ImGui handles the press, the drag and the hover itself. The <code>click</code> that follows on the node has a <code>pointerType</code> and is ignored. The text field is the exception: its press isn't sent to ImGui, so the browser focuses the node, raises the keyboard and places the caret.</li>
<li><strong>Tab order.</strong> The nodes are in the canvas in the order ImGui submitted the widgets, so the browser's Tab order is ImGui's layout order. The page sends ImGui no keys at all.</li>
<li><strong>Nothing is drawn from the DOM</strong> unless the second checkbox is on. Then the text node is uploaded with <code>texElementSubImage2D()</code> while it has focus and ImGui draws it as an image in the text field's frame.</li>
</ul>
<h3>Findings</h3>
<ul>
<li><strong>Yes: an undrawn element in the canvas gives an ImGui widget a role, a name, a state and a box.</strong> Measured in headless Chromium 157 on 2026-11-21. The accessibility tree read through the DevTools protocol has a group with a textbox "Title", a checkbox "Autosave" (checked), a slider "Volume" (value, minimum 0, maximum 100), a button "Save", a status node and a button "Advanced" (expanded false), in that order. <code>getBoundingClientRect()</code> of all 14 nodes equals the rectangle ImGui reported, with a difference of 0 CSS px.</li>
<li><strong>The element doesn't have to be drawn.</strong> No call draws a node and no texture is uploaded. <code>updateElementGeometry()</code> works on an element that is only laid out. The node's CSS width and height set the size of the box, and <code>canvasTransform</code> sets its place.</li>
<li><strong>Hit testing follows.</strong> <code>elementFromPoint()</code> at each visible widget returns its node. A press therefore lands on the node, and the page forwards it to ImGui from a capture listener on the canvas.</li>
<li><strong><code>canvasClip</code> cuts the hit box but not the reported box.</strong> With the ImGui window's clip rectangle as <code>canvasClip</code>, the part of a row that is scrolled under the title bar isn't hit. <code>getBoundingClientRect()</code> still returns the whole row, and returns positions outside the canvas for rows that are scrolled out. The outlines on this page show that.</li>
<li><strong>A scrolled-out widget keeps its node.</strong> ImGui still submits it, so it still has a rectangle. Tab reaches it, and the <code>focus</code> event makes ImGui scroll it into view with <code>ScrollToItem()</code>. A widget that ImGui stops submitting (inside a closed header) loses its node on that frame. If that node had focus, focus goes to <code>&lt;body&gt;</code>.</li>
<li><strong>Tab order is DOM order.</strong> Tab from the page heading went through Title, Autosave, Volume, Save, Advanced and the eight checkboxes in ImGui's order, then on to the controls under the canvas. Space toggled the checkbox, the arrow keys moved the slider and Enter pressed Save. ImGui received no key events.</li>
<li><strong>ImGui accepts a press from outside through its keyboard activation ids.</strong> Setting <code>NavActivateId</code>, <code>NavActivateDownId</code> and <code>NavActivatePressedId</code> to the widget's id before the widget is submitted makes <code>ImGui::Button()</code> return true and <code>CollapsingHeader()</code> toggle. These are fields from <code>imgui_internal.h</code>. The checkbox, slider and text field are set by writing to the variable the widget draws.</li>
<li><strong>ImGui draws the focus ring.</strong> A <code>focus</code> event calls <code>SetFocusID()</code> for the widget and sets <code>NavCursorVisible</code> to what <code>:focus-visible</code> says for the node. ImGui only keeps the ring when <code>ImGuiConfigFlags_NavEnableKeyboard</code> is set.</li>
<li><strong>The text field works on the DOM node's input.</strong> ImGui's own <code>InputText()</code> takes characters only from key events, which is why it raised no phone keyboard on <a href="https://html-in-canvas.page/imgui-dom/">the earlier page</a>. Here the node has focus and takes the typing, and its value is copied into the ImGui buffer on every <code>input</code> event. ImGui draws the text, and a caret and selection at the node's <code>selectionStart</code> and <code>selectionEnd</code>.</li>
<li><strong>A click in the text needs the two fonts to agree.</strong> The browser places the caret with the node's own text layout. ImGui's font drew "Quarterly report" 128 px wide and the node's monospace font laid it out 144.5 px wide, so a click landed on the wrong letter. The page sets <code>letter-spacing</code> on the node so that the widths match. With two fixed-pitch fonts a mouse drag from x 40 to x 120 then selected letters 3 to 13, which is where ImGui drew them. With a proportional font this would be approximate.</li>
<li><strong>Drawing the focused node is the alternative.</strong> With the second checkbox on, the text node is uploaded with <code>texElementSubImage2D()</code> while it has focus and ImGui draws that image in the frame, so the caret, the selection and the letters are the browser's. The live check counted 0 uploads before focus, 2 while focused and 0 after blur.</li>
<li><strong>Fallback content isn't enough.</strong> The same elements as plain children of a canvas without <code>layoutsubtree</code> are in the accessibility tree with the same roles and names and take focus, and Space, Enter and the arrow keys work on them. But every box is 0 by 0 at 0, 0, <code>getClientRects()</code> is empty, <code>elementFromPoint()</code> returns the canvas, and typing into the focused text input changed nothing. Measured in Chromium 157 with the API turned off.</li>
<li><strong>Frames only on demand.</strong> 0 ImGui frames and 0 geometry calls during 30 idle animation frames. Geometry is sent only for a node whose rectangle changed.</li>
<li><strong>Not verified with a screen reader.</strong> TalkBack, VoiceOver, NVDA and JAWS weren't run. The bounds a screen reader receives weren't read directly: the DevTools protocol gives the accessibility tree without bounds, and the boxes above come from the DOM. Whether a screen reader's activate gesture arrives as a <code>click</code> with an empty <code>pointerType</code>, and whether touch exploration finds the nodes, needs a phone.</li>
</ul>
<p>
This page follows <a href="https://html-in-canvas.page/imgui-dom/">DOM elements in a Dear ImGui app</a>, which shows real elements as ImGui images. Here the direction is reversed: ImGui's own widgets get elements.
Source: <a href="https://github.com/PaulKinlan/html-in-canvas-demos/tree/main/native/toolkit-aria">native/toolkit-aria</a>. Dear ImGui is MIT licensed.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/toolkit-aria.md">findings/toolkit-aria.md</a> in the repository.</p>
<p>Measured in C157 (headless shell 157.0.8103.78, 2.625 device scale, 412 px wide, touch) on 2026-11-21. Dear ImGui 1.92.5, Emscripten 4.0.7, WebGL2, no GLFW or SDL. Source in <code>native/toolkit-aria/</code>. The build is 420 KB of WebAssembly and 96 KB of JavaScript. The page has 16 live checks; all 16 pass in C157. The accessibility tree was read with CDP <code>Accessibility.getFullAXTree</code> and Playwright <code>ariaSnapshot()</code>.</p>
<p>The question: ImGui draws its own button, checkbox, slider and text field as pixels. Can each widget have a real DOM node inside the canvas that is never drawn, placed with <code>updateElementGeometry()</code>, so that the accessibility tree, hit testing, Tab order and focus describe ImGui's widgets?</p>
<h3>Route (a): nodes in a <code>layoutsubtree</code> canvas that are never drawn</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td><code>updateElementGeometry(el, { canvasTransform, canvasClip })</code> on an element that is never drawn</td><td>works</td><td>14 nodes, 0 texture uploads, 0 draw calls for any node. The node's CSS width and height give the box size.</td></tr>
<tr><td><code>getBoundingClientRect()</code></td><td>the rectangle ImGui drew</td><td>Largest difference over 14 nodes: 0 CSS px. The unit of <code>canvasTransform</code> measured 1 (CSS px) on this canvas at 2.625 device scale.</td></tr>
<tr><td><code>elementFromPoint()</code></td><td>the node</td><td>9 of 9 widgets that were in view.</td></tr>
<tr><td>Accessibility tree (CDP)</td><td>role, name and state are right</td><td><code>group "Document settings, drawn by Dear ImGui"</code> with <code>textbox "Title"</code> (value "Quarterly report"), <code>checkbox "Autosave"</code> (checked true), <code>slider "Volume"</code> (value 41, valuemin 0, valuemax 100), <code>button "Save"</code>, <code>status</code> (live polite) with the text, <code>button "Advanced"</code> (expanded false), 8 more checkboxes, in ImGui's order.</td></tr>
<tr><td>Boxes of those accessibility nodes</td><td>match, read from the DOM</td><td>CDP <code>DOM.getContentQuads</code> for each accessibility node's DOM node gives the ImGui rectangle (for example Save 48 by 33 at the button). CDP does not return bounds in accessibility nodes, so the bounds sent to a platform accessibility API were not read.</td></tr>
<tr><td><code>computedRole</code>, <code>computedName</code></td><td>not exposed</td><td>Both are <code>undefined</code> in this build. The live check prints them where a browser has them.</td></tr>
<tr><td><code>aria-valuetext</code> on the range node</td><td>set, not confirmed in the tree</td><td>The attribute is "41 %". CDP reports the <code>valuetext</code> property as empty. It reports the same for a <code>role="slider"</code> element outside any canvas, so this says nothing about the canvas.</td></tr>
<tr><td><code>canvasClip</code> = the ImGui window's clip rectangle</td><td>cuts the hit box only</td><td>A row scrolled 8 px under the title bar: the point above the clip edge hits <code>&lt;canvas&gt;</code>, the point below hits the node. <code>getBoundingClientRect()</code> still reports the whole row.</td></tr>
<tr><td>A widget scrolled out of the window</td><td>keeps its node and its true rectangle</td><td>For example Title at y -182 and Surveys at y 605 on a 420 px canvas. ImGui still submits a scrolled-out widget, so it has a rectangle.</td></tr>
<tr><td>Focus on a scrolled-out node</td><td>ImGui scrolls to it</td><td><code>focus</code> event, then <code>SetFocusID()</code> and <code>ScrollToItem()</code>. Surveys went from y 605 to y 379 and was hit by <code>elementFromPoint()</code>.</td></tr>
<tr><td>A widget that is no longer submitted</td><td>node removed that frame</td><td>Closing the "Advanced" header: 16 nodes to 14. A removed node that had focus leaves focus on <code>&lt;body&gt;</code>.</td></tr>
<tr><td>DOM order = ImGui submission order</td><td>works</td><td>New nodes are inserted at the position ImGui submitted them. Opening the header puts Spell check and Reset after Advanced.</td></tr>
<tr><td>Tab order (real Tab key, Playwright)</td><td>ImGui's order</td><td>From the page heading: Title, Autosave, Volume, Save, Advanced, the 8 checkboxes, then the two controls under the canvas. The status node is skipped. ImGui gets no key events.</td></tr>
<tr><td><code>click()</code> on the button node</td><td><code>ImGui::Button()</code> returns true</td><td>The page sets <code>g.NavActivateId</code>, <code>NavActivateDownId</code> and <code>NavActivatePressedId</code> to the id before the widget is submitted. The same call toggles <code>CollapsingHeader()</code>.</td></tr>
<tr><td>Enter on the focused button node, Space on the checkbox node, arrows on the range node</td><td>work</td><td>Enter saved, Space toggled Autosave in ImGui, two ArrowRight presses moved the ImGui slider from 73 to 75.</td></tr>
<tr><td><code>input</code> on the range node</td><td>sets the ImGui slider</td><td>ImGui formats the value and the page writes it back as <code>aria-valuetext</code>.</td></tr>
<tr><td>Pointer in ImGui to DOM state</td><td>works</td><td>A touch tap on the ImGui checkbox changed the node's <code>checked</code>; a tap at 80% of the slider set the node's value to 83 and <code>aria-valuetext</code> to "83 %".</td></tr>
<tr><td>A press lands on a node, ImGui still handles it</td><td>works</td><td>Capture listener on the canvas forwards pointer events. The <code>click</code> that follows has a <code>pointerType</code> and is ignored, so nothing is pressed twice. Touch drag on the slider and touch scrolling of the window work.</td></tr>
<tr><td>DOM focus to ImGui focus</td><td>works</td><td><code>ui_nav_id()</code> equals the widget id. ImGui's ring is drawn when the node matches <code>:focus-visible</code> and is off after <code>blur</code>. After a touch tap on Save the ring is off.</td></tr>
<tr><td>Text typed in the text node</td><td>reaches the <code>InputText()</code> buffer</td><td>Including "é" and "東京" (ImGui's default font has no glyph for the last two). ImGui's <code>InputText()</code> is never active; ImGui draws the buffer, and a caret and selection from <code>selectionStart</code> and <code>selectionEnd</code>.</td></tr>
<tr><td>Click to place the caret</td><td>exact after matching text widths</td><td>ImGui: "Quarterly report" is 128 px. Node (15 px monospace): 144.5 px. With <code>letter-spacing</code> set to (128 - 144.5) / 16 the same click gives the same letter: a mouse drag from x 40 to x 120 selected 3 to 13. Before the fix it selected 2 to 11.</td></tr>
<tr><td>Idle</td><td>0 frames</td><td>0 ImGui frames and 0 <code>updateElementGeometry()</code> calls during 30 animation frames.</td></tr>
<tr><td>Page stability</td><td>passes</td><td><code>check:jank</code> with and without <code>--checks</code>: cls 0, scroll 0 px, focus moves 0, 1 WebGL context, 0 lost.</td></tr></tbody></table>
<h3>Route (b): the same nodes as fallback content of a canvas without <code>layoutsubtree</code></h3>
<p>Measured two ways: a plain canvas made by the live check, and the whole page run with <code>--disable-blink-features=CanvasDrawElement</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Accessibility tree</td><td>same roles and names</td><td>group, textbox "Title", checkbox "Autosave", slider "Volume", button "Save", status, button "Advanced".</td></tr>
<tr><td><code>getBoundingClientRect()</code></td><td>0 by 0 at 0, 0</td><td><code>getClientRects()</code> is empty, <code>offsetWidth</code> is 0.</td></tr>
<tr><td><code>elementFromPoint()</code> over the canvas</td><td><code>&lt;canvas&gt;</code></td><td>No node can be hit.</td></tr>
<tr><td><code>focus()</code> and Tab</td><td>work</td><td>Same Tab order. ImGui still scrolls to the focused widget and draws the ring.</td></tr>
<tr><td>Space on the checkbox, arrow on the slider, Enter on the button</td><td>work</td><td>ImGui state changed each time.</td></tr>
<tr><td>Typing in the focused text input</td><td>does nothing</td><td>Focus was on the input, End and two letters were typed, the value did not change. The text field cannot be edited as fallback content.</td></tr>
<tr><td>Pointer</td><td>ImGui only</td><td>Taps reach ImGui through the canvas. DOM focus does not follow a tap, except that the page focuses the text node itself.</td></tr></tbody></table>
<h3>Route (c): draw the focused text node with <code>texElementSubImage2D()</code></h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Upload the text node only while it has focus and draw it as an ImGui image in the frame</td><td>works</td><td>0 uploads before focus, 2 while focused, 0 after blur. ImGui draws its own text with a clear colour while the image is shown. The caret, selection and glyphs are then the browser's, so the font matching of route (a) is not needed. Off by default on the page.</td></tr>
<tr><td>Draw only the node's focus ring</td><td>not tried</td><td>ImGui's own ring was enough.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>ImGui cleared <code>NavCursorVisible</code> every frame until <code>ImGuiConfigFlags_NavEnableKeyboard</code> was set. The page still sends ImGui no keys.</li>
<li><code>GetItemRectMin()</code> and <code>GetItemRectMax()</code> include the label of a slider or text field. <code>g.LastItemData.NavRect</code> is the frame alone.</li>
<li>An <code>ImGuiID</code> above 2^31 arrives in JavaScript as a negative number. It is used as a map key and passed back unchanged.</li>
<li>Calling an exported function with <code>stringToUTF8OnStack()</code> from JavaScript needs <code>stackSave()</code> and <code>stackRestore()</code> around it, or the stack grows by the string on every call.</li>
<li>A touch tap on the text field after its text had been selected and the field blurred restored the old selection (0 to 16) in headless Chromium. A plain <code>&lt;input&gt;</code> outside a canvas did the same in the same run, so it is not caused by the canvas.</li>
<li>Hiding ImGui's text with a clear <code>ImGuiCol_Text</code> for route (c) also hid the widget's label. The label is drawn again by hand.</li>
<li>The outlines show <code>getBoundingClientRect()</code>, which ignores <code>canvasClip</code>, so the outline of a half scrolled row is drawn over ImGui's title bar.</li></ul>
<h3>Not verified</h3>
<ul><li>Screen readers: TalkBack (A159), VoiceOver, NVDA, JAWS. To verify: open the page with TalkBack on, swipe through the canvas and listen for "Title, edit box", "Autosave, checkbox, checked", "Volume, slider, 40 percent", "Save, button"; check that the focus rectangle TalkBack draws sits on the ImGui widget; double tap Save and read the status line.</li>
<li>The bounds a platform accessibility API receives. CDP gives none. <code>chrome://accessibility</code> on a desktop build, or the Android accessibility node info, would show them.</li>
<li>Whether a screen reader's activate gesture arrives as a <code>click</code> with an empty <code>pointerType</code>. If it arrives as a pointer sequence instead, ImGui handles it as a pointer press, which also works.</li>
<li>Whether a screen reader's slider increment fires <code>input</code> on the range node.</li>
<li>Whether <code>aria-valuetext</code> and the <code>role="status"</code> change are announced.</li>
<li>Touch exploration (finding a node by moving a finger over the canvas).</li>
<li>A real phone: the on-screen keyboard over the canvas when the text node is tapped, IME composition (route (c) should show the composition marks, route (a) shows only committed text), touch selection handles.</li>
<li>Recovery from a lost WebGL context. The page shows a message.</li>
<li>C153 and A159.</li></ul>
<h3>Open ideas</h3>
<ul><li>The same helper for a second toolkit (egui has AccessKit output; Qt has QAccessible) to compare how much of the tree a toolkit can report by itself.</li>
<li>Combo boxes and popups: a <code>&lt;select&gt;</code> node, or <code>role="listbox"</code> nodes for the popup's rows, with ImGui's window order deciding which nodes are hit.</li>
<li>Headings and landmarks from <code>SeparatorText()</code> and window titles.</li></ul>
<p><a href="https://html-in-canvas.page/toolkit-aria/">Open An accessibility tree for a Dear ImGui app</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Occlusion without a guard in a Dear ImGui app</title>
<link>https://html-in-canvas.page/toolkit-occlusion/</link>
<guid isPermaLink="true">https://html-in-canvas.page/toolkit-occlusion/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>updateElementGeometry</category>
<category>hit testing</category>
<description>An ImGui window dragged over a DOM field must stop the field taking the pointer. Nine routes are tried: a script guard, canvasClip, CSS clip-path and mask, a blocker element, inert, and a plain element above the canvas.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/toolkit-occlusion/"><img src="https://html-in-canvas.page/toolkit-occlusion/social.jpg" width="1200" height="630" alt="The page &quot;Occlusion without a guard in a Dear ImGui app&quot;"></a></p>
<p><strong>Question:</strong> Can the geometry given to updateElementGeometry() say that an ImGui window covers a DOM field, so that no script has to decide it at event time?</p>
<p><strong>Short answer:</strong> Not with canvasClip, which is one rectangle. Yes with an empty blocker element placed last, and with CSS clip-path on the field at the cost of one texture upload per move.</p>
<p>
A DOM field in a Dear ImGui window still takes the pointer when a second ImGui window is drawn over it. <a href="https://html-in-canvas.page/imgui-dom/">The first ImGui page</a>
asks ImGui what is on top at every pointer event. I tried nine ways to say it in advance. Drag Window A or B over a field, pick a route, and read the table.
</p>
<h3>How it works</h3>
<ul>
<li><strong>The app reports, the page decides.</strong> After each ImGui frame the C++ side gives the page the rectangle of every field, the clip rectangle of the form window, and the rectangle of every window above the form in ImGui's z-order. The form is kept behind the other windows (<code>ImGuiWindowFlags_NoBringToFrontOnFocus</code>).</li>
<li><strong>A route is a function from those rectangles to what the browser is told.</strong> Routes 1 to 3 only call <code>updateElementGeometry()</code> on the field. Routes 5 and 7 also write CSS or an attribute on the field. Route 6 places two more elements in the canvas. Route 8 moves two elements that are outside the canvas.</li>
<li><strong>The pointer.</strong> ImGui has no input of its own in a browser, so one listener sends it every pointer event whose target isn't a field: the canvas, a blocker or an overlay. That listener is the same on every route. Only the guard adds a question to ImGui before it lets a field keep an event.</li>
<li><strong>The measurement.</strong> 96 sample points per field (16 by 6). For each point ImGui answers whether a window above the form takes the pointer there, and <code>elementFromPoint()</code> answers which element the browser finds. A wrong hit is a covered point where the browser finds the field. A lost hit is an uncovered point where it does not. An attribute on the canvas is toggled first, because Chromium 157 keeps a stale hit-test answer after a geometry change.</li>
<li><strong>When it runs.</strong> The table is filled once at the start, when the route changes, and a quarter of a second after the last frame in which a window moved. ImGui draws only when an event or a <code>paint</code> asked for frames.</li>
</ul>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, at a device scale of 2.625 with touch input. The numbers are from the live checks: 96 sample points on the textarea, window A in four positions (over all of it, over its right side, across its middle, over one corner).</p>
<ul>
<li><strong><code>canvasClip</code> is one rectangle and can't be more.</strong> It is a <code>DOMRectInit</code> dictionary in the element's own coordinates. An array of two <code>DOMRect</code>s, an array of four numbers, a <code>Path2D</code>, a <code>DOMRectList</code> and a <code>DOMQuad</code> don't throw: each is read as a dictionary with no members, which is an empty rectangle, and the field loses its whole hit box. A string or a number throws <code>TypeError</code>. A <code>radii</code> member isn't read. A negative width is normalised. A <code>NaN</code> or infinite member leaves the earlier clip in place, and so does leaving <code>canvasClip</code> out. A zero-size rectangle removes the hit box and leaves <code>getBoundingClientRect()</code> where it was.</li>
<li><strong>Route 3, the largest visible rectangle, has no wrong hits and loses part of the field.</strong> Window over all of the field or over one side: exact. Window across the middle: 36 of 72 visible points lost, because only one of the two halves can be the clip. Window over a corner: 14 of 68 lost, the short arm of the L. Over the four positions 74% of the visible points take the pointer.</li>
<li><strong>Route 5a, CSS <code>clip-path</code> on the field, is exact.</strong> The hit test of a drawable child follows <code>clip-path</code>: <code>path()</code>, <code>path(evenodd, …)</code> with a hole and <code>polygon()</code> all work. 0 wrong hits and 0 lost hits in all four positions. The clipped part also leaves the field's texture (the texel reads <code>rgba(0, 0, 0, 0)</code>), which ImGui draws over, and a texel in the uncovered part is unchanged. The cost is one <code>paint</code> event and one texture upload each time the window moves: 10 of each for 10 moves.</li>
<li><strong>Route 5b, CSS <code>mask</code>, doesn't work.</strong> The mask cuts the texture and costs the same uploads, and the hit test ignores it: every covered point still hits the field.</li>
<li><strong>Route 6, a blocker element, is exact and costs no repaint.</strong> An empty 1 by 1 px <code>&lt;div drawable&gt;</code> is scaled to the window's rectangle with <code>canvasTransform</code>. 0 wrong hits, 0 lost hits, 0 <code>paint</code> events and 0 uploads for 10 moves, and one <code>updateElementGeometry()</code> call per move. A press on the blocker is sent to ImGui, which drags the window.</li>
<li><strong>Where two hit boxes overlap, the most recent <code>updateElementGeometry()</code> call wins.</strong> <code>z-index</code> on either element and the order of the elements in the DOM play no part. A call with the same values as before still raises the element. A repaint of the field does not. So the page places the blockers again, back to front, after any field was placed.</li>
<li><strong>Routes 7a and 7b are all or nothing.</strong> <code>inert</code> or <code>pointer-events: none</code> while any part is covered removes the wrong hits and every hit on the visible part: 0% of the visible points take the pointer in the three partial positions. <code>inert</code> is the only route that also stops <code>focus()</code> and takes the field out of the Tab order.</li>
<li><strong>Route 7c: one element has one hit box.</strong> A second <code>updateElementGeometry()</code> call replaces the first. An element has one parent, so two drawable wrappers can't hold the same field.</li>
<li><strong>Route 8, a plain element above the canvas, is exact and uses no canvas API.</strong> An absolutely positioned <code>&lt;div&gt;</code> beside the canvas, moved with one style write per window move. It only works when the page that owns the canvas can put elements over it.</li>
<li><strong>Route 2, the guard, leaves the browser's hit test wrong.</strong> All 190 covered points still hit the field. The listener asks ImGui, stops the event and parks the field off the canvas. With touch input the browser had already chosen the field: a tap on a covered point didn't focus it, but a drag that started there got <code>pointercancel</code> and scrolled the page, because <code>touch-action: none</code> on the canvas didn't apply to a touch that began on the field. On routes 3, 5a, 6 and 8 the same drag moved the window.</li>
<li><strong>Tab still reaches a covered field.</strong> With the textarea fully covered, Tab from the input went to the textarea on every route except <code>inert</code>. <code>getBoundingClientRect()</code> stayed where ImGui drew the field on every route. No route here takes a covered field out of the accessibility tree without also making a partly covered field unusable.</li>
<li><strong>ImGui claims more than it draws.</strong> <code>FindHoveredWindowEx()</code> gives a window the pointer up to 4 px outside its drawn edge (<code>TouchExtraPadding</code>, <code>WindowBorderHoverPadding</code>). The routes use that larger rectangle. ImGui windows here have square corners. A rounded window would need <code>clip-path</code> on the blocker, which wasn't tried.</li>
<li><strong>Not verified on a phone.</strong> The touch results are from CDP touch events in headless Chromium 157. An ImGui popup or combo over a field isn't in this app.</li>
</ul>
<p>
This page follows <a href="https://html-in-canvas.page/imgui-dom/">DOM elements in a Dear ImGui app</a>.
Source: <a href="https://github.com/PaulKinlan/html-in-canvas-demos/tree/main/native/toolkit-occlusion">native/toolkit-occlusion</a>. Dear ImGui is MIT licensed.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/toolkit-occlusion.md">findings/toolkit-occlusion.md</a> in the repository.</p>
<p>Measured in C157 (headless Chromium 157.0.8103.78, 2.625 device scale, touch) on 2026-11-21. Dear ImGui 1.92.5, Emscripten, WebGL2, no GLFW or SDL. Source in <code>native/toolkit-occlusion/</code>. The build is 362 KB of WebAssembly and 91 KB of JavaScript. PLAN.md backlog item 27.2.</p>
<p>The question: a DOM field shown in an ImGui window keeps taking the pointer when another ImGui window is drawn over it. <code>/imgui-dom/</code> asks ImGui what is on top in a listener at every pointer event (the guard). Can the geometry say it in advance.</p>
<p>How the numbers were made. The live checks run a second copy of the app in a 360 px wide frame. Each field has 96 sample points (16 by 6). For each point ImGui answers whether a window above the form takes the pointer there (<code>FindHoveredWindowEx()</code>), and <code>elementFromPoint()</code> answers which element the browser finds, after an attribute on the canvas is toggled. A wrong hit is a covered point where the browser finds the field. A lost hit is an uncovered point where it does not. Window A is put in four positions over the textarea: over all of it (96 points covered), over its right side (42), across its middle (24), over its bottom right corner (28). The tables give the textarea's numbers.</p>
<h3>Routes</h3>
<table><thead><tr><th>Route</th><th>Wrong hits (full, side, middle, corner)</th><th>Lost hits of visible points (side, middle, corner)</th><th>Visible points that take the pointer</th><th>Result</th></tr></thead><tbody><tr><td>1. No handling</td><td>96, 42, 24, 28</td><td>0 of 54, 0 of 72, 0 of 68</td><td>100%</td><td>fails: every covered point hits the field</td></tr>
<tr><td>2. Guard: a capture listener asks ImGui at each pointer event on a field</td><td>96, 42, 24, 28 in the browser's hit test; 0 get through the listener</td><td>0, 0, 0</td><td>100%</td><td>works for mouse and tap; the hit test stays wrong</td></tr>
<tr><td>3. <code>canvasClip</code> as the largest visible rectangle</td><td>0, 0, 0, 0</td><td>0 of 54, 36 of 72, 14 of 68</td><td>74% over the four positions (middle 50%, corner 79%)</td><td>fails for a split field and an L shape</td></tr>
<tr><td>4. <code>canvasClip</code> as anything other than one rectangle</td><td>see the next table</td><td></td><td></td><td>not accepted</td></tr>
<tr><td>5a. CSS <code>clip-path: path()</code> on the field</td><td>0, 0, 0, 0</td><td>0, 0, 0</td><td>100%</td><td>works, with one upload per move</td></tr>
<tr><td>5b. CSS <code>mask</code> on the field</td><td>96, 42, 24, 28</td><td>0, 0, 0</td><td>100%</td><td>fails: hit testing ignores a mask</td></tr>
<tr><td>6. Blocker: an empty drawable <code>&lt;div&gt;</code> per window, placed after the fields</td><td>0, 0, 0, 0</td><td>0, 0, 0</td><td>100%</td><td>works</td></tr>
<tr><td>7a. <code>inert</code> while any part is covered</td><td>0, 0, 0, 0</td><td>54 of 54, 72 of 72, 68 of 68</td><td>0% in the partial positions</td><td>fails: all or nothing</td></tr>
<tr><td>7b. <code>pointer-events: none</code> while any part is covered</td><td>0, 0, 0, 0</td><td>54 of 54, 72 of 72, 68 of 68</td><td>0% in the partial positions</td><td>fails: all or nothing</td></tr>
<tr><td>7c. Two hit boxes for one element</td><td></td><td></td><td></td><td>not possible: the second <code>updateElementGeometry()</code> call replaces the first</td></tr>
<tr><td>8. A plain <code>&lt;div&gt;</code> above the canvas, outside it</td><td>0, 0, 0, 0</td><td>0, 0, 0</td><td>100%</td><td>works, with no canvas API</td></tr></tbody></table>
<p>Cost of ten 4 px moves of window A across the textarea, and the questions put to ImGui during ten pointer events at a covered point:</p>
<table><thead><tr><th>Route</th><th><code>paint</code> events</th><th>Texture uploads</th><th><code>updateElementGeometry()</code> calls</th><th>Style writes</th><th>Questions to ImGui in 10 pointer events</th></tr></thead><tbody><tr><td>1. No handling</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>2. Guard</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1, then the field is parked off the canvas and the canvas gets the events</td></tr>
<tr><td>3. <code>canvasClip</code> rectangle</td><td>0</td><td>0</td><td>10</td><td>0</td><td>0</td></tr>
<tr><td>5a. <code>clip-path</code></td><td>10</td><td>10</td><td>0</td><td>10</td><td>0</td></tr>
<tr><td>5b. <code>mask</code></td><td>10</td><td>10</td><td>0</td><td>10</td><td>0</td></tr>
<tr><td>6. Blocker</td><td>0</td><td>0</td><td>10</td><td>0</td><td>0</td></tr>
<tr><td>7a. <code>inert</code>, 7b. <code>pointer-events</code></td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>8. Element above the canvas</td><td>0</td><td>0</td><td>0</td><td>10</td><td>0</td></tr></tbody></table>
<p>On every route one listener sends ImGui each pointer event whose target is not a field, because ImGui has no other input in a browser. "Questions" counts only the calls that ask ImGui what is on top.</p>
<h3>What <code>canvasClip</code> accepts (route 4)</h3>
<p>Before each try the clip was the right half of the input. The try asked for the left half, or for the two outer parts in the case of the array.</p>
<table><thead><tr><th>Value</th><th>Result</th></tr></thead><tbody><tr><td><code>new DOMRect(x, y, w, h)</code>, <code>{ x, y, width, height }</code></td><td>used. The rectangle is in the element's own coordinates, before <code>canvasTransform</code></td></tr>
<tr><td>An array of two <code>DOMRect</code>s, an array of four numbers, a <code>Path2D</code>, a <code>DOMRectList</code>, a <code>DOMQuad</code>, <code>{}</code>, <code>null</code></td><td>no throw. Read as a dictionary with no members, which is an empty rectangle: the field has no hit box at all</td></tr>
<tr><td>A string (<code>'inset(0 50% 0 0)'</code>), a number</td><td>throws <code>TypeError</code> ("not of type 'DOMRectInit'"). The earlier clip stays</td></tr>
<tr><td><code>{ x, y, width, height, radii: [20] }</code></td><td>used as a plain rectangle. The point 1 px inside the corner still hits</td></tr>
<tr><td>A zero-size or zero-width rectangle</td><td>no hit box. <code>getBoundingClientRect()</code> stays where the transform put the field</td></tr>
<tr><td>A negative width (<code>w/2, 0, -w/2, h</code>)</td><td>normalised: the left half</td></tr>
<tr><td>A <code>NaN</code> x, an infinite width</td><td>the earlier clip stays. The transform in the same call is applied (measured in a scratch probe, not in a live check)</td></tr>
<tr><td>No <code>canvasClip</code> member</td><td>the earlier clip stays. A clip is removed by passing a rectangle larger than the element</td></tr></tbody></table>
<h3>Other results</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>Does hit testing of a drawable child follow CSS <code>clip-path</code></td><td>yes</td><td><code>path()</code> with several rectangles, <code>path(evenodd, …)</code> with a hole (hit pattern across the input 11001) and <code>polygon()</code> (11100)</td></tr>
<tr><td>Does the clipped part leave the texture</td><td>yes</td><td>A texel in the covered corner read <code>rgba(28, 43, 74, 255)</code> without the clip and <code>rgba(0, 0, 0, 0)</code> with it. A texel in the uncovered part was the same before and after. ImGui draws its window over the hole</td></tr>
<tr><td>Which element wins where two hit boxes overlap</td><td>the one whose <code>updateElementGeometry()</code> call was the most recent</td><td>Field then blocker: blocker. Blocker then field: field. A repeat of the same field call raises the field again</td></tr>
<tr><td><code>z-index</code> on either element</td><td>no effect</td><td>Tried with 9 on the field and with 9 on the blocker, in both call orders</td></tr>
<tr><td>DOM order of the two elements</td><td>no effect</td><td>Blocker first and blocker last among the canvas's children, in both call orders</td></tr>
<tr><td>A repaint of the field after the blocker was placed</td><td>the blocker stays on top</td><td>The field's value was changed and uploaded again</td></tr>
<tr><td>A blocker of 1 by 1 CSS px scaled by <code>canvasTransform</code></td><td>works</td><td>The hit box is the scaled rectangle. No layout and no <code>paint</code> event when it moves. A blocker resized with CSS width and height fired one <code>paint</code> event per change (scratch probe)</td></tr>
<tr><td><code>focus()</code> on a fully covered field</td><td>works on every route except <code>inert</code></td><td>Live check, inside the fixture frame</td></tr>
<tr><td>Tab from the input with the textarea fully covered</td><td>goes to the textarea on every route except <code>inert</code>, where it goes to the select</td><td>Playwright key press on the page</td></tr>
<tr><td><code>getBoundingClientRect()</code> of a fully covered field</td><td>where ImGui drew it, on every route</td><td>Routes 3 and 5a use a zero-size <code>canvasClip</code> for a fully covered field instead of moving it off the canvas</td></tr>
<tr><td>Touch: drag an ImGui window over a field, on every route</td><td>works</td><td>CDP touch events at 412 px wide</td></tr>
<tr><td>Touch: tap a covered point of the textarea</td><td>routes 1 and 5b focus the textarea. The others do not</td><td></td></tr>
<tr><td>Touch: start a drag on a covered point of the textarea</td><td>routes 3, 5a, 6, 7a, 7b, 8: the window moves. Routes 1, 2 and 5b: <code>pointercancel</code>, and the page scrolls</td><td>The browser picked the field as the target before any script ran. <code>touch-action: none</code> on the canvas did not apply to the touch that began on the field. The guard moved the window by two steps and then lost the pointer</td></tr>
<tr><td>Touch: tap a visible point of a partly covered textarea</td><td>focuses it on routes 1, 2, 3, 5a, 5b, 6, 8. Not on 7a and 7b</td><td></td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>ImGui gives a window the pointer in a rectangle larger than the one it draws: <code>FindHoveredWindowEx()</code> pads <code>OuterRectClipped</code> by <code>TouchExtraPadding</code>, or by <code>WindowBorderHoverPadding</code> for a resizable window (4 px here). The app reports the padded rectangle, so the routes and ImGui's own answer agree at every sample point.</li>
<li>While a window is being dragged, <code>FindHoveredWindowEx(pos, false, …)</code> answers the moving window for every point. The measurement uses the form with <code>true</code>, which ignores the drag.</li>
<li>An omitted <code>canvasClip</code> does not clear the clip. The first probe read "ignored" where the truth was "the earlier value stays", until each try started from a known clip.</li>
<li>Every <code>updateElementGeometry()</code> call on a field raises it above the blockers, including a call with unchanged values. The page sends a field's geometry only when it changed and places every blocker again in the same frame.</li>
<li>Two covering windows that overlap each other make <code>path(evenodd, …)</code> with one hole per window wrong: the doubly covered part comes back. The route builds the visible part as rectangles that do not overlap and writes them as one <code>path()</code>.</li>
<li><code>outline.hidden = false</code> did nothing on an <code>&lt;svg&gt;</code> element: <code>hidden</code> is not a property of SVG elements. The page toggles the attribute.</li>
<li><code>elementFromPoint()</code> answers <code>null</code> for a point outside the viewport. The table says how many sample points were not tested, and measures again when more of the canvas scrolls into view.</li>
<li>A stage 560 px tall with a long introduction put the whole canvas below the first screen at 412 by 840. The route selector is the only control above the canvas now.</li></ul>
<h3>Not verified</h3>
<ul><li>A real phone (A159). The touch results are CDP touch events in headless Chromium 157. What would verify it: open the page, pick each route, drag window A over the textarea and tap the covered part.</li>
<li>Screen readers. A covered field keeps its bounds and its place in the Tab order on every route except <code>inert</code>. Whether a reader announces it was not run.</li>
<li>An ImGui popup, combo or tooltip over a field. This app has only root windows. The blocker route would need one blocker per popup.</li>
<li>A window with rounded corners. <code>clip-path</code> on the blocker element was not tried.</li>
<li>More than two covering windows. The page has two blockers and two overlay elements in its markup.</li>
<li>A form that is not behind every other window. The call order should express any z-order (place elements back to front), inferred from the two-element result and not run.</li>
<li>The cost of the <code>clip-path</code> route on a real GPU. One upload per move was counted. Frame time was not measured.</li>
<li>Whether the "most recent call wins" order is specified or an accident of Chromium 157.</li>
<li>Nested drawables. In a scratch probe a drawable <code>&lt;input&gt;</code> inside a drawable <code>&lt;div&gt;</code> took its own <code>updateElementGeometry()</code> call without a throw and was hit at its own place. Not built into the page.</li></ul>
<p><a href="https://html-in-canvas.page/toolkit-occlusion/">Open Occlusion without a guard in a Dear ImGui app</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A tooltip, a modal and toasts beside the top layer</title>
<link>https://html-in-canvas.page/top-layer/</link>
<guid isPermaLink="true">https://html-in-canvas.page/top-layer/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>dialog</category>
<category>tooltip</category>
<category>top layer</category>
<category>drawElementImage</category>
<description>The top layer is painted by the page, not by a canvas. A tooltip drawn by the canvas from title text, a scene that moves away behind a showModal() dialog, and toasts that are &lt;dialog open&gt; elements kept out of the top layer so the canvas can animate them.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/top-layer/"><img src="https://html-in-canvas.page/top-layer/social.jpg" width="1200" height="630" alt="The page &quot;A tooltip, a modal and toasts beside the top layer&quot;"></a></p>
<p><strong>Question:</strong> A canvas can't draw the top layer or a native tooltip. What can it do for a tooltip, a modal dialog and a toast instead?</p>
<p><strong>Short answer:</strong> Three things, each measured in Chromium 157. It can draw its own tooltip element where a term was drawn, because getClientRects() gives the drawn boxes. It can draw its scene moving away behind a modal dialog from dialog.open. And it can draw and animate a dialog that has the open attribute and position: static, which isn't in the top layer.</p>
<p>
Three ideas from the <a href="https://html-in-canvas.page/elements/">element catalogue</a>. A native tooltip, a modal dialog and a popover are painted by the page
in the top layer, upright and outside any canvas, so a canvas can't draw them. Each demo takes one of them and does the part a canvas
can do: it draws its own tooltip from the <code>title</code> text, it draws the scene behind a modal dialog moving away, and it draws
toasts that are dialogs kept out of the top layer.
</p>
<h3>How it works</h3>
<p>An element's picture holds what the element paints in normal flow. The top layer is a separate list that the browser paints over the whole page: modal dialogs, popovers, and the picker of a customisable select. A native <code>title</code> tooltip is drawn by the browser's own interface, outside the page. None of these can be passed to <code>drawElementImage()</code>. The three demos work beside that limit in three ways:</p>
<ul>
<li><b>Replace it.</b> The tooltip is an ordinary element with <code>role="tooltip"</code>, drawn by the canvas where the term was drawn. <code>getClientRects()</code> of an inline element returns its drawn boxes, also when the draw was rotated.</li>
<li><b>Draw the other half.</b> The modal dialog stays in the top layer. The canvas draws what is behind it.</li>
<li><b>Keep it out of the top layer.</b> A dialog with the <code>open</code> attribute isn't in the top layer. It needs <code>position: static</code> to be laid out inside the canvas.</li>
</ul>
<p>A fourth idea from the same list, a menu that opens flat from buttons drawn in perspective, is already built as <a href="https://html-in-canvas.page/popovers/">/popovers/</a>: there the popover stays in the top layer and CSS anchor positioning keeps it on the drawn button.</p>
<h3>Findings</h3>
<p>Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch. Not yet run on a phone.</p>
<ul>
<li><b>A canvas can draw its own tooltip at the drawn place of a term.</b> <code>getClientRects()</code> of an inline element inside a rotated draw returned a box whose middle was 0.1 px from where the rotation puts it. The box is the bounding box of the rotated text: 42.4 by 29.5 px for a 39 by 19 px span.</li>
<li><b>The drawn tooltip opens by mouse, by tap and by keyboard focus.</b> <code>pointerover</code>, <code>click</code> and <code>focusin</code> reach the terms where they are drawn. The page moves each <code>title</code> to <code>data-tip</code>, so the browser's own tooltip doesn't appear as well, and points the term at the tooltip element with <code>aria-describedby</code>.</li>
<li><b>An open popover isn't in the picture of the element that holds it.</b> None of 50 sampled pixels of the drawn box had the popover's colour. The same holds for a modal dialog (measured on <a href="https://html-in-canvas.page/elements/">/elements/</a>).</li>
<li><b>While a dialog is modal, the scene in the canvas is still drawn and can't be hit.</b> <code>elementFromPoint()</code> at the drawn scene returned the dialog. With <code>closedby="any"</code> a tap on the drawn scene closed the dialog. After it closed, a checkbox in the scene took a tap again.</li>
<li><b>The canvas can stand in for <code>::backdrop</code> for its own scene.</b> It draws the scene at 84% size through <code>blur()</code>, <code>saturate()</code> and <code>brightness()</code> filters from <code>dialog.open</code>, and the <code>toggle</code> and <code>close</code> events of the dialog ask for the paint. A filter on a draw doesn't change where the element is found.</li>
<li><b>A <code>&lt;dialog open&gt;</code> is drawn as a <code>drawable</code> child if it is <code>position: static</code>.</b> Its buttons are found where it is drawn, also while it slides. A dialog added while the page runs is drawn from the next paint.</li>
<li><b>Not verified:</b> everything on a phone. In particular a long press on a term (Android may show its own menu), the on-screen keyboard over the toast form, and where Android centres the modal dialog while the keyboard is open. A screen reader on the tooltip and on the toasts wasn't tried.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/top-layer.md">findings/top-layer.md</a> in the repository.</p>
<p>Ideas 18.2 and 18.3 of the backlog in PLAN.md, and "Toast stack in the scene" from the element catalogue. Measured in headless Chromium 157 (C157) on 2026-11-21 with a mouse, a keyboard and emulated touch at 412 px wide. The page's four live checks pass there, and <code>node tools/top-layer/check.mjs</code> drives the three demos with real input (22 steps, all pass). Nothing here has been run on a phone.</p>
<p>The question: a canvas cannot draw the top layer or a native tooltip. What can it do for a tooltip, a modal dialog and a toast instead?</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Place of an inline element inside a rotated draw</td><td><code>getClientRects()</code> gives it</td><td>A paragraph drawn rotated by 0.3 rad: the middle of a span's box was 0.1 px from the rotated place. The box is the bounding box of the rotated text (42.4 by 29.5 px for a 39 by 19 px span).</td></tr>
<tr><td>Tooltip as a <code>drawable</code> element with <code>role="tooltip"</code>, drawn above the term</td><td>works</td><td>Its text is set when a term becomes active, and it is drawn with a tail by the canvas. It has <code>pointer-events: none</code>.</td></tr>
<tr><td>Opening it by mouse, tap and keyboard</td><td>works</td><td><code>pointerover</code> (mouse), <code>click</code> (tap) and <code>focusin</code> on the drawn terms. Escape and a tap elsewhere close it. Terms that are not focusable get <code>tabindex="0"</code>.</td></tr>
<tr><td>The browser's own <code>title</code> tooltip</td><td>removed</td><td>Each <code>title</code> is moved to <code>data-tip</code> at start. Whether headless Chromium would have shown the native tooltip is not known: it is painted outside the page.</td></tr>
<tr><td>The term drawn again, larger, in a clipped box</td><td>works</td><td>The card is drawn a second time through a clip at the term's box with a scale of 1.28, then marked with a <code>multiply</code> fill. A draw inside an empty clip puts the hit region back.</td></tr>
<tr><td>A link with a <code>title</code>, tapped</td><td>navigates</td><td>The tap follows the link, so on touch its tooltip is seen only with a mouse or the keyboard.</td></tr>
<tr><td>An open popover inside a <code>drawable</code> element</td><td>not in the picture</td><td>0 of 50 sampled pixels had the popover's colour (live check).</td></tr>
<tr><td>Scene behind a modal dialog</td><td>drawn by the canvas from <code>dialog.open</code></td><td>84% size, <code>blur(3.5px) saturate(0.15) brightness(0.55)</code> over a dark fill. The <code>toggle</code> and <code>close</code> events of the dialog ask for a paint. The canvas total brightness fell below 60% and came back to within 1% after closing.</td></tr>
<tr><td>Hit testing the drawn scene while the dialog is modal</td><td>returns the dialog</td><td>The scene is inert. With <code>closedby="any"</code> a tap on it closed the dialog with no code.</td></tr>
<tr><td>The scene after the dialog closed</td><td>works</td><td>A checkbox took a tap. A filter on a draw does not move the hit region (live check).</td></tr>
<tr><td><code>&lt;dialog open&gt;</code> as a <code>drawable</code> child of the canvas</td><td>drawn, buttons found</td><td>Needs <code>position: static</code>. Live check: pixel 29,35,48 inside it and its button returned by <code>elementFromPoint()</code>.</td></tr>
<tr><td>Toasts added while the page runs</td><td>drawn from the next paint</td><td>The first draw of a new element can fail because it has no picture yet. The paint loop tries again in the next frame.</td></tr>
<tr><td>A toast that is leaving</td><td><code>inert</code>, then removed</td><td>Its hit region is shrunk to a point before it is removed.</td></tr>
<tr><td>A lost context</td><td>plain HTML</td><td>One <code>contextlost</code> event stops all three and shows the elements as plain HTML (3 boxes). Tested by dispatching the event.</td></tr></tbody></table>
<p>Idea 18.1, "Menu that stays readable on a tilted toolbar", is not built again here: <code>/popovers/</code> already opens popovers from buttons drawn in perspective and keeps them on the drawn button with CSS anchor positioning.</p>
<h3>Things that bit</h3>
<ul><li>A live check must not open a modal dialog, because <code>showModal()</code> moves focus and the jank guard counts that. The modal facts are covered by <code>tools/top-layer/check.mjs</code> with real taps.</li>
<li><code>python3 -m http.server</code> stopped between two test runs. Start it again before running the tool.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 on Android: all three demos by touch.</li>
<li>A long press on a term. Android may show its own selection or link menu.</li>
<li>The on-screen keyboard over the toast form, and where Android centres the modal dialog while the keyboard is open.</li>
<li>A screen reader on the tooltip (<code>aria-describedby</code> to a drawn element) and on the toasts.</li>
<li>Whether the native <code>title</code> tooltip would appear at the drawn place of a term with a real mouse, if the titles were left in place.</li></ul>
<p><a href="https://html-in-canvas.page/top-layer/">Open A tooltip, a modal and toasts beside the top layer</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A lens that translates</title>
<link>https://html-in-canvas.page/translate-lens/</link>
<guid isPermaLink="true">https://html-in-canvas.page/translate-lens/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Translator</category>
<category>Summarizer</category>
<category>Rewriter</category>
<category>drawElementImage</category>
<description>A circle over an article shows the same text in French, Spanish, German or Japanese, in simpler words, or as one-line summaries. The canvas draws a converted copy of the article inside the circle, lined up block by block, and the original still takes clicks.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/translate-lens/"><img src="https://html-in-canvas.page/translate-lens/social.jpg" width="1200" height="630" alt="The page &quot;A lens that translates&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas draw a translated, simplified or summarised copy of an element inside a lens, lined up with the original, and which on-device language APIs can fill the copy?</p>
<p><strong>Short answer:</strong> A second drawable child holds the copy. Drawing it once per block, clipped and moved to the original block, keeps the two lined up. The APIs weren't usable in the test browser; recorded text stands in.</p>
<p>
The canvas draws a translated, simplified or summarised copy of this article inside the circle. Move the mouse over it, or drag the circle
with a finger. The link, the button and the editable sentence under the circle still work.
</p>
<h3>How it works</h3>
<p>
<code>drawElementImage()</code> draws a child of the canvas wherever the 2D transform and clip say. The page keeps two children: the article,
and a copy of it made by <a href="https://html-in-canvas.page/lib/text-twin.js"><code>TextTwin</code></a>. The original is drawn once at its layout position, which is also
where it receives clicks. The copy is <code>inert</code> and is only drawn inside the lens circle. A translated paragraph rarely has the same
number of lines as the original, so each block of the copy is drawn separately and moved to the top of the block it belongs to.
</p>
<p>
The text comes from a provider. With <code>Translator</code>, <code>Rewriter</code> or <code>Summarizer</code> in the browser, the provider calls
the on-device model. Without them it answers from a table written in advance for this article, and a block whose text isn't in the table is
hatched in red. The line under the demo says which one is in use.
</p>
<h3>Findings</h3>
<ul>
<li><strong>A copy drawn inside a clip works as a lens with one 2D context.</strong> The original keeps its hit testing because it's drawn at its layout position and the copy is <code>inert</code>. <code>elementFromPoint()</code> under the lens returns the original's link.</li>
<li><strong>Without alignment the copy drifts.</strong> In a 340 px column the recorded German copy starts its third block 24 px lower than the English original and its last blocks 48 px lower (measured by the live check). The "Line up" menu shows it.</li>
<li><strong>Two ways to line up a block were tried, and both work.</strong> The first draws the whole copy once for each block under the lens, clipped to the original block's rows and moved. The second puts the <code>drawable</code> attribute on every block of the copy and passes each block to <code>drawElementImage()</code> by itself, which is one small draw per block.</li>
<li><strong>A <code>drawable</code> descendant is left out of its ancestor's picture.</strong> In Chromium 157, once a block of the copy has the attribute, drawing the copy as a whole leaves a hole where the block is. A list item drawn by itself also has no bullet, because the marker is outside its box. So a page picks one of the two ways for a given copy.</li>
<li><strong><code>getBoundingClientRect()</code> couldn't be used to measure the copy.</strong> For a child of a drawable canvas it reports where the element was last drawn. The copy is drawn moved and scaled, so the page measures blocks with <code>offsetTop</code> and <code>offsetLeft</code>.</li>
<li><strong>"Shrunk to fit" keeps all the text of a longer block but makes it smaller.</strong> "By its top" keeps the size and cuts off lines that don't fit. A shorter block leaves empty rows in both.</li>
<li><strong>Translating one text node at a time keeps inline elements but loses word order across them.</strong> "measured from <b>chart datum</b>, the lowest level" is three text nodes. The recorded German puts the verb in the third node, which a per-node model call can't know to do. Rewriting and summarising work on the whole block and return plain text, so the link and the bold word aren't in the copy.</li>
<li><strong>The built-in AI APIs weren't usable in the test browser.</strong> In headless Chromium 157 <code>Summarizer</code> and <code>LanguageModel</code> report "downloadable", <code>LanguageDetector</code> reports "unavailable", <code>Rewriter</code> is missing and <code>Translator.availability()</code> never settles. No model can be downloaded in the cloud container, so the code paths that call <code>Translator</code>, <code>Rewriter</code> and <code>Summarizer</code> haven't been run. The line under the demo shows what this browser reports.</li>
<li><strong>The recorded Welsh, Cornish, Breton and Manx haven't been checked by a speaker.</strong> They were written by a language model for this page, and the Cornish and Manx in particular are likely to hold errors. The page says so under the demo when one of them is chosen. Whether <code>Translator</code> has any of the four on a device isn't verified: when it does not, the lens stays on the recorded text and says why.</li>
<li><strong>Not verified:</strong> model download and speed on Android, the quality of per-node translation from a real model, and the drag on a real touch screen.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/translate-lens.md">findings/translate-lens.md</a> in the repository.</p>
<p>Measured in headless Chromium 157 on 2026-11-21. The built-in AI interfaces had no model there, so the rows that need one are marked.</p>
<table><thead><tr><th>What</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A converted copy of an element drawn inside a clip (a lens)</td><td>works</td><td>Two drawable children, one 2D context. The original is drawn at its layout position and keeps hit testing; the copy is <code>inert</code>.</td></tr>
<tr><td>The copy in its own layout, German against English, 340 px column</td><td>drifts</td><td>Block tops are off by 0, 0, 24, 48, 48 px.</td></tr>
<tr><td>The whole copy drawn once per block, clipped and moved to the original block</td><td>works</td><td>0 px of drift. One draw of the copy per block under the lens.</td></tr>
<tr><td>A <code>drawable</code> descendant passed to <code>drawElementImage()</code> by itself</td><td>works</td><td>One small draw per block. The element takes clicks where it was drawn.</td></tr>
<tr><td>The same descendant in its drawable ancestor's picture</td><td>left out</td><td>The ancestor is drawn with a hole where the descendant is. A list item drawn by itself has no bullet.</td></tr>
<tr><td><code>getBoundingClientRect()</code> on a canvas child that is drawn moved or scaled</td><td>reports the drawn box</td><td>Use <code>offsetTop</code> and <code>offsetLeft</code> to measure layout.</td></tr>
<tr><td>A card swapped for its summary when its text would be under 9 px</td><td>works</td><td>The undrawn element keeps its last hit area, so it is made <code>inert</code>.</td></tr>
<tr><td><code>Translator.availability()</code></td><td>never settles</td><td>Headless Chromium 157. The page gives up after 3 s.</td></tr>
<tr><td><code>Summarizer</code>, <code>LanguageModel</code> availability</td><td>"downloadable"</td><td>No download is possible in the container. <code>Rewriter</code> is missing, <code>LanguageDetector</code> is "unavailable".</td></tr>
<tr><td><code>LanguageModel.prompt()</code> with a <code>responseConstraint</code>, no model</td><td>resolves with prose</td><td>The answer starts "On-device" and is not JSON. Not verified with a model.</td></tr>
<tr><td><code>navigator.modelContext</code> (WebMCP)</td><td>missing</td><td>Registration is written for <code>registerTool()</code> and <code>provideContext()</code> and has not been run.</td></tr>
<tr><td>A tool call shown by a shader through four CSS custom properties</td><td>works</td><td>The lean and the marker position are registered properties with CSS transitions. The tool resolves after the animation.</td></tr>
<tr><td>Hit testing on the form while it leans in perspective</td><td>works</td><td>Four controls found at their drawn centres, within 0.4 px of the effect's matrix.</td></tr>
<tr><td>A form control named <code>length</code></td><td>cannot be reached by name</td><td><code>form.elements.length</code> is the number of controls.</td></tr>
<tr><td>Words matched against the accessible names of the buttons that are not hidden, then <code>click()</code></td><td>works</td><td><code>/voice/</code>. No command list: the names come from the DOM, and change when the other set of switches is shown.</td></tr>
<tr><td>A press from script starting the shader's ring</td><td>works</td><td><code>click()</code> fires no pointer event, so the page calls the surface's <code>poke(x, y)</code>.</td></tr>
<tr><td>A custom highlight on a transcript word, in the texture</td><td>drawn</td><td>575 pixels of the highlight colour in the read-back picture.</td></tr>
<tr><td><code>SpeechRecognition.available({ processLocally: true })</code></td><td>crashes the tab</td><td>Headless Chromium 157. <code>/voice/</code> asks only after a tap, and its check refuses in an automated browser.</td></tr>
<tr><td><code>SpeechRecognition</code>, <code>phrases</code>, <code>SpeechRecognitionPhrase</code>, <code>install()</code></td><td>present</td><td>Headless Chromium 157. <code>SpeechRecognitionResult</code> is not a global there, so <code>speechStartTime</code> cannot be detected.</td></tr></tbody></table>
<p>Not verified: every path that calls a model (<code>Translator</code>, <code>Rewriter</code>, <code>Summarizer</code>, the Prompt API planner and image prompt), WebMCP with a real agent, speech recognition of any kind (no microphone), whether <code>phrases</code> changes what is recognised, result timestamps, WebGPU on screen, and touch dragging of the lens on a real phone.</p>
<p>The recorded Welsh, Cornish, Breton and Manx text on <code>/translate-lens/</code> was written by a language model and has not been checked by a speaker. Whether <code>Translator</code> has any of the four on a device is not verified.</p>
<p><a href="https://html-in-canvas.page/translate-lens/">Open A lens that translates</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Transport lab 2: newer routes</title>
<link>https://html-in-canvas.page/transports-2/</link>
<guid isPermaLink="true">https://html-in-canvas.page/transports-2/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebRTC</category>
<category>SharedArrayBuffer</category>
<category>WebTransport</category>
<category>Element Capture</category>
<description>WebRTC sender settings that keep text at full size, an RTCDataChannel in a worker, SharedArrayBuffer under Document-Isolation-Policy, WebTransport, Element Capture, and a test of what stops when the tab is frozen.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/transports-2/"><img src="https://html-in-canvas.page/transports-2/social.jpg" width="1200" height="630" alt="The page &quot;Transport lab 2: newer routes&quot;"></a></p>
<p><strong>Question:</strong> Which transport APIs from Chrome 130 to 160 carry a drawn element, and what stops when the browser freezes the source tab?</p>
<p><strong>Short answer:</strong> <code>maintain-framerate-and-resolution</code> keeps a 960×540 element at 960×540 where the default shrinks it to 320×180. A frame with <code>Document-Isolation-Policy</code> gets shared memory. WebTransport has no server here.</p>
<p>
More routes for getting a drawn element to another thread, document or device, using APIs from Chrome 130 to 160:
WebRTC sender settings that keep text sharp, an <code>RTCDataChannel</code> moved to a worker, <code>SharedArrayBuffer</code> under
<code>Document-Isolation-Policy</code>, WebTransport datagrams and Element Capture. The <a href="https://html-in-canvas.page/transports/">first lab</a> has the other fifty.
</p>
<h3>Findings</h3>
<ul>
<li><strong><code>degradationPreference: 'maintain-framerate-and-resolution'</code> keeps the element at its own size.</strong> With the default (<code>balanced</code>) and a low bitrate, WebRTC shrinks the picture, which blurs text first. With this value the encoder keeps the size and the page is responsible for sending fewer frames.</li>
<li><strong><code>scaleResolutionDownTo</code> sends a smaller stream without resizing the canvas.</strong> The source canvas stays at full size for the page; the phone gets a picture no larger than the size given.</li>
<li><strong>An <code>RTCDataChannel</code> transfers to a worker, once, before anything is sent on it.</strong> Transfer it in the <code>datachannel</code> event. After that, input from the far device is parsed off the main thread.</li>
<li><strong><code>Document-Isolation-Policy</code> isolates one frame.</strong> The frame gets <code>SharedArrayBuffer</code> and <code>Atomics.wait</code>; the page around it stays as it was and keeps its cross-origin frames. This page isn't isolated, so the same code fails here, which the row before it shows.</li>
<li><strong>WebTransport has no server on this site.</strong> The Cloudflare Workers documentation lists no way to accept a WebTransport session, so the datagram row fails with the browser's error. The row's code hasn't been run against a real server. Add <code>?wt=https://host/path</code> to point the row at an echo server of your own.</li>
<li><strong>Element Capture can't be answered by a headless browser,</strong> so those rows have only been run by hand. See the detail text they print.</li>
<li><strong>Freezing hasn't been measured yet.</strong> Neither test browser can be made to freeze a tab (the DevTools lifecycle command changes nothing there, and no <code>freeze</code> event fires), so the freeze test above has only run with the tab visible. It needs a phone. The remote and cross-tab pages now report on their own page how long they were stopped.</li>
<li><strong><code>track.stats</code> doesn't exist on a canvas capture track.</strong> The frame counters are only on camera and screen capture tracks, so a canvas stream has to count its own frames.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/transports-2.md">findings/transports-2.md</a> in the repository.</p>
<p>Demo 18 (<code>transport-2</code>) of the Chrome APIs plan.</p>
<p>Page <code>/transports-2/</code>, Chromium 157 headless, 2026-11-21. Rows run when a button is pressed and each row removes its canvas before the next starts.</p>
<table><thead><tr><th>Route</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>WebRTC at 40 kbit/s, default <code>degradationPreference</code></td><td>works, shrunk</td><td>A 960×540 element arrives as 320×180; <code>qualityLimitationReason</code> is <code>bandwidth</code>.</td></tr>
<tr><td>WebRTC at 40 kbit/s, <code>maintain-framerate-and-resolution</code></td><td>works</td><td>Arrives as 960×540. The page has to lower the frame rate itself.</td></tr>
<tr><td><code>encodings[0].scaleResolutionDownTo = { maxWidth: 320, maxHeight: 180 }</code></td><td>works</td><td>The canvas stays 960×540 and the far end decodes 320×180.</td></tr>
<tr><td><code>VideoFrame.metadata().rtpTimestamp</code> on received frames</td><td>works</td><td>Read through <code>MediaStreamTrackProcessor</code>; 90 kHz clock.</td></tr>
<tr><td><code>track.stats</code> on a <code>canvas.captureStream()</code> track</td><td>fails</td><td><code>undefined</code>. The frame counters exist only on camera and screen tracks.</td></tr>
<tr><td><code>RTCDataChannel</code> transferred to a worker</td><td>works</td><td>Transfer it inside the <code>datachannel</code> event, before anything is sent.</td></tr>
<tr><td><code>SharedArrayBuffer</code> on a normal page</td><td>fails</td><td>Expected: not cross-origin isolated.</td></tr>
<tr><td><code>SharedArrayBuffer</code> in a frame served with <code>Document-Isolation-Policy: isolate-and-credentialless</code></td><td>works</td><td>A worker reads the pixels in place after <code>Atomics.notify</code>. The embedding page stays non-isolated, a frame from the other origin still loads inside the isolated frame, and an <code>ImageBitmap</code> posted out of it arrives intact.</td></tr>
<tr><td><code>Uint8Array.prototype.toBase64()</code> / <code>fromBase64()</code></td><td>works</td><td>PNG bytes as text over a BroadcastChannel.</td></tr>
<tr><td>WebTransport datagrams</td><td>fails</td><td>No server: the Cloudflare Workers documentation lists no WebTransport endpoint. <code>?wt=&lt;url&gt;</code> points the row at another server; the row has never run against one.</td></tr></tbody></table>
<p>Not run:</p>
<ul><li><strong>Element Capture.</strong> <code>getDisplayMedia({ preferCurrentTab: true })</code> is accepted with <code>--auto-accept-this-tab-capture</code> but fails with <code>NotReadableError: Could not start video source</code> in both test browsers, headless and under Xvfb. The three rows (a plain element, a drawable canvas, an element that is a child of a drawable canvas) need a desktop Chrome and a person.</li>
<li><strong>Freezing.</strong> <code>Page.setWebLifecycleState({ state: 'frozen' })</code> changes nothing in either test browser: timers keep running, frames keep arriving at a viewer, and no <code>freeze</code> event fires. The page has a freeze test (timer, <code>paint</code> events, dedicated worker, SharedWorker, WebSocket: longest stop for each) that needs a phone hidden for 90 seconds. <code>lib/freeze-log.js</code> records <code>freeze</code>, <code>resume</code> and timer gaps, and <code>/remote/</code> and <code>/cross-tab/</code> show how long they were stopped.</li></ul>
<h3>Not verified</h3>
<ul><li>Element Capture of a plain element, a drawable canvas and a child of a drawable canvas. Tab capture fails to start in C157 and C153 (<code>NotReadableError</code>), headless and under Xvfb. The Element Capture button on <code>/transports-2/</code> in desktop Chrome would verify it.</li>
<li>What stops while a tab is frozen. The DevTools lifecycle command does not freeze a tab in either test browser. The freeze test on <code>/transports-2/</code> on a phone, with the tab hidden for 90 seconds, would verify it.</li>
<li>WebTransport against a real server. <code>?wt=&lt;url&gt;</code> points the row at one.</li></ul>
<p><a href="https://html-in-canvas.page/transports-2/">Open Transport lab 2: newer routes</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Code that types itself</title>
<link>https://html-in-canvas.page/typed-code/</link>
<guid isPermaLink="true">https://html-in-canvas.page/typed-code/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>pre</category>
<category>code</category>
<category>Range.getClientRects</category>
<category>CSS Custom Highlight API</category>
<category>drawElementImage</category>
<description>A code block that holds all of its text while the canvas draws it one character at a time, with a caret, a glow and wrong keys that exist only in the picture. Selecting or copying at any moment gives the whole block.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/typed-code/"><img src="https://html-in-canvas.page/typed-code/social.jpg" width="1200" height="630" alt="The page &quot;Code that types itself&quot;"></a></p>
<p><strong>Question:</strong> Can a canvas reveal the glyphs of a code block in order while the text stays complete, selectable and copyable in the document?</p>
<p><strong>Short answer:</strong> Yes. A clip path made of character boxes over one <code>drawElementImage()</code> call hides the rest. Syntax colours from <code>::highlight()</code> are in the picture.</p>
<p>
The code block below holds all of its text from the start. The canvas draws only the characters that have been typed so far, with a caret, a glow on the newest characters and an occasional wrong key that is
corrected. The wrong characters exist only in the picture. Select the text or press Copy while it's typing: the selection and the clipboard get the whole block. The code shown is the function that draws it.
</p>
<h3>How it works</h3>
<p>The <code>&lt;pre&gt;</code> is a child of the canvas and contains the complete code as one text node. The page measures a box for every character with <code>Range.getClientRects()</code>.
On each <code>paint</code> it builds a clip path from the boxes of the first <em>n</em> characters and calls <code>drawElementImage()</code> once. The clip hides the characters that aren't typed yet.</p>
<p>The syntax colours come from the CSS Custom Highlight API: the script registers ranges for comments, strings, keywords, numbers and calls, and <code>::highlight()</code> rules colour them. So the text needs no
spans, and character <em>n</em> of the text node is character <em>n</em> of the animation.</p>
<p>A wrong key is drawn with the nine-argument <code>drawElementImage()</code>: the box of a different letter somewhere else in the block is copied to the caret position, held for a moment and then removed. The text node never changes.
The element's hit region covers the whole block, so text that isn't drawn yet can still be selected, and the boxes of the selection are added to the clip so that selected text shows.</p>
<h3>Findings</h3>
<ul>
<li>A clip path of character boxes over one <code>drawElementImage()</code> call reveals text glyph by glyph. With 16 lines of code the paint took under 1 ms in the test browser.</li>
<li>The text that isn't drawn is still in the document. A <code>Range</code> over the block returns all of it, <code>elementFromPoint()</code> on an undrawn character returns the <code>&lt;code&gt;</code> element, and a selection can be made there.</li>
<li><code>::highlight()</code> colours from the CSS Custom Highlight API are part of the element's picture.</li>
<li>A piece of the element drawn at another place with the nine-argument <code>drawElementImage()</code> shows a character that isn't in the text at that position. The last draw decides the hit region, so the page ends each paint
with a draw of the whole element inside an empty clip. <code>updateElementGeometry()</code> alone leaves the hit region the size of the last piece.</li>
<li>Not verified: Chrome 159 for Android, long-press selection of text that isn't drawn yet, and find-in-page on it. Pause the demo at the start, long-press in the empty part of the block and check that a selection appears.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/typed-code.md">findings/typed-code.md</a> in the repository.</p>
<p>Measured in Chromium 157 (headless shell), 2026-11-21, at 412 px wide with a device scale factor of 2 and at 1100 px wide. Not yet run on the test phone (Chrome 159 for Android).</p>
<p>Idea built: "Code that types itself" from <code>public/elements/ideas.js</code> (rank 2, text).</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Does a clip path of character boxes over one <code>drawElementImage()</code> call reveal glyphs one at a time?</td><td>measured: yes</td><td>With 4 of 25 characters typed, characters 1 and 3 drew 130 and 137 pixels, characters 7 and 16 drew 0.</td></tr>
<tr><td>Is the undrawn text still in the document?</td><td>measured: yes</td><td>A <code>Range</code> over the block returns all 25 characters. <code>elementFromPoint()</code> on the box of an undrawn character returns <code>&lt;code&gt;</code>, and <code>caretPositionFromPoint()</code> gives offset 15 in the text node.</td></tr>
<tr><td>Are <code>::highlight()</code> colours from the CSS Custom Highlight API in the picture?</td><td>measured: yes</td><td>431 orange pixels in a keyword. The block is one text node with no spans.</td></tr>
<tr><td>Can a character that is not in the text be shown?</td><td>measured: yes</td><td>The box of another letter copied to the caret position with the nine-argument <code>drawElementImage()</code> drew 208 pixels. <code>textContent</code> did not change.</td></tr>
<tr><td>Does the page stop its frame loop when typing ends?</td><td>measured: yes</td><td>0 <code>requestAnimationFrame()</code> calls after the end. The caret blinks from a 530 ms timer while the canvas is on screen.</td></tr>
<tr><td>Is selected text drawn before it is typed?</td><td>measured: yes, for boxes passed to the reveal</td><td>The selection's line boxes are added to the clip. A real selection made by pointer was not driven in the test browser.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The demo text is <code>reveal.toString()</code>, the function that draws the block. Lines had to stay under 46 characters to fit a 412 px screen without wrapping.</li>
<li>The last <code>drawElementImage()</code> call decides the hit region. After the glow and wrong-key pieces, a whole draw inside an empty clip (<code>home()</code>) puts it back. <code>updateElementGeometry()</code> moves the region but leaves it the size of the last piece (2 of 36 points hit).</li>
<li>A newline has no box. The caret takes the right edge of the previous character there.</li>
<li>Highlight ranges are registered once on shared <code>Highlight</code> objects. Fixtures add their own ranges to the same objects.</li></ul>
<h3>Not verified</h3>
<ul><li>Chrome 159 for Android: long-press selection of text that is not drawn yet, and the Copy button (the Clipboard API needs a user gesture and a secure context).</li>
<li>Find-in-page on undrawn text. It should match, because the text is in the document, and the match highlight would be clipped away. Not measurable in the test browser.</li>
<li>A real copy of a partial selection (the <code>copy</code> event listener reports its length).</li></ul>
<h3>Open ideas</h3>
<ul><li>Type a diff: the reveal runs over <code>&lt;ins&gt;</code> and <code>&lt;del&gt;</code> elements and removes the deleted glyphs one at a time.</li>
<li>Drive the position from a scroll timeline, so the code is typed as the reader scrolls.</li>
<li>The same clip for prose that is "spoken" by speech synthesis, using <code>boundary</code> events as the position.</li></ul>
<p><a href="https://html-in-canvas.page/typed-code/">Open Code that types itself</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Video lab: title editor, cinema sound, wide gamut, timeline skin, WebGPU player</title>
<link>https://html-in-canvas.page/video-lab/</link>
<guid isPermaLink="true">https://html-in-canvas.page/video-lab/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>texElementSubImage2D</category>
<category>exportFrames</category>
<category>PannerNode</category>
<category>display-p3</category>
<category>WebGPU</category>
<description>Five experiments with a video as a canvas child. Clips and editable HTML title cards joined by shader transitions and exported to a file, a cinema screen in a 3D room with the sound placed at the screen, a wide-gamut clip in a Display P3 canvas, a shader on the native timeline only, and the player shader in WGSL.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/video-lab/"><img src="https://html-in-canvas.page/video-lab/social.jpg" width="1200" height="630" alt="The page &quot;Video lab: title editor, cinema sound, wide gamut, timeline skin, WebGPU player&quot;"></a></p>
<p><strong>Question:</strong> Can clips and HTML title cards be cut together and exported from one canvas, does a video keep its native controls and wide-gamut colours on a quad in perspective and in a Display P3 canvas, and does the player shader run in WebGPU?</p>
<p><strong>Short answer:</strong> Yes for the editor, the export, the controls in perspective, the sound position, the timeline skin and Display P3. An HDR10 clip is tone-mapped to at most 1.0. The WGSL shader was rendered off screen only: the test browser can't show a WebGPU canvas.</p>
<p>Five experiments with a <code>&lt;video&gt;</code> as a canvas child. The first three share one WebGL canvas: choose a scene with the buttons. In the editor, tap the text of a title card on the canvas and type. In the cinema, tap play on the screen, then tap a seat. The last two sections have their own canvases further down.</p>
<h3>How it works</h3>
<ul>
<li><strong>One WebGL context.</strong> The three scenes are sets of children of one canvas. A scene that isn't chosen has its elements hidden, so they aren't painted and take no taps. One fragment shader has a mode for each kind of quad.</li>
<li><strong>Title editor.</strong> Each shot is an element the size of the canvas: a <code>&lt;video&gt;</code> in a wrapper, or a title card. At any time one or two shots are uploaded with <code>texElementSubImage2D()</code>. Where two overlap, the shader mixes them with the chosen transition. The shot in front has its hit box on the canvas, so a title card is edited in place.</li>
<li><strong>Export.</strong> <code>exportFrames()</code> from <code>lib/video-export.js</code> seeks one video per frame. Here it is given an object with <code>currentTime</code>, <code>pause()</code> and a <code>seeked</code> event that seeks every video on the timeline and sets each card's <code>--t</code>. Each frame is one <code>paint</code> and one <code>VideoFrame</code> from the canvas.</li>
<li><strong>Cinema screen.</strong> The screen, its reflection and the floor are three quads with perspective matrices. The same matrix, with the conversion to CSS pixels, goes to <code>updateElementGeometry()</code>, so the video's native controls and the seat buttons take taps where they are drawn. The page doesn't use three.js here: the site allows one WebGL context per page and the scenes share it.</li>
<li><strong>Sound.</strong> <code>createMediaElementSource(video)</code> feeds a <code>PannerNode</code> at the centre of the screen. The <code>AudioListener</code> is at the chosen seat. The two meters are the level of each output channel, measured by two <code>AnalyserNode</code>s.</li>
<li><strong>Timeline skin.</strong> For one paint, <code>::-webkit-media-controls-timeline</code> gets a magenta background. That picture goes into a spare texture, the bottom quarter is read once, and the box of the magenta pixels is the timeline. The shader replaces the pixels inside the box and adds a glow at the playhead.</li>
<li><strong>Wide gamut.</strong> The two canvases differ only in the <code>colorSpace</code> of their 2D context. Pixels are never read from them: each is copied with <code>drawImage()</code> into a plain canvas with the same colour space, and that copy is read with <code>getImageData({ colorSpace: 'display-p3' })</code>.</li>
<li><strong>WebGPU player.</strong> <code>GPUQueue.drawElementImageToTexture()</code> uploads the controls. <code>copyExternalImageToTexture()</code> uploads the frame from the same video. The device comes from the page's shared <code>webgpu()</code>. Where that gives none, the player is drawn with the 2D context and no shader.</li>
</ul>
<h3>Findings</h3>
<p>Measured in Chromium 157, headless, software rendering, on 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: video clips and HTML title cards as shots, with shader transitions.</strong> All five transitions start on the first shot and end on the second. Three of them are the GLSL of <code>/transitions/</code>, unchanged.</li>
<li><strong>Works: a title card edited on a WebGL canvas.</strong> The card in front takes the tap, the caret and the typing.</li>
<li><strong>Works: frame-by-frame export of several videos and cards.</strong> The exported file holds the frames that were asked for. It has no sound track: <code>exportFrames()</code> takes the sound of one video.</li>
<li><strong>Works: native video controls and buttons on quads in perspective.</strong> <code>elementFromPoint()</code> returns the video at the projected centre of the screen and a seat button at its projected centre.</li>
<li><strong>Works: a <code>PannerNode</code> at the screen.</strong> Rendered offline, a seat on the left hears more in the right ear and a seat near the screen hears more than one at the back.</li>
<li><strong>Works: a shader on the timeline only.</strong> With the skin on and off, no pixel outside the strip and its glow changes.</li>
<li><strong>Works: a wide-gamut video keeps its colours in a Display P3 canvas.</strong> The red of a BT.2020 clip reads as Display P3 (118, 0, 3) there and as (119, 21, 12) from the sRGB canvas. <code>drawElementImage()</code> and <code>drawImage(video)</code> give the same values.</li>
<li><strong>Limit: an HDR10 video is tone-mapped to at most 1.0.</strong> In a float16 Display P3 canvas the brightest part of a PQ clip is 1.0, the same as in an 8-bit canvas.</li>
<li><strong>Works off screen: the WGSL shader.</strong> On the software adapter the pass was rendered to a texture and read back. <code>copyExternalImageToTexture(video)</code> failed there, and the frame came through <code>createImageBitmap(video)</code>.</li>
<li><strong>Not verified: WebGPU on screen, an HDR screen, and the sound through real speakers.</strong> The test browser has none of them.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-lab.md">findings/video-lab.md</a> in the repository.</p>
<p>Measured in Chromium 157 headless (C157), software rendering and software video decoding, 2026-11-21. The WebGPU rows were measured with the SwiftShader software adapter (<code>--enable-unsafe-webgpu --enable-unsafe-swiftshader</code>), off screen: the pass draws into a texture that is read back. Rows marked "script" were driven by Playwright with real mouse or touch input, at 1000 px wide and at 412 px wide with touch and a device scale factor of 2.625. Nothing here was run on a phone.</p>
<p>The page builds ideas 22.1 to 22.5 of the backlog in <code>PLAN.md</code>. The first three share one WebGL canvas and one context (<code>lib/element-gl.js</code>), chosen by three buttons. A scene that is not chosen has its elements hidden.</p>
<h3>Title editor (22.1)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Video clips and HTML title cards as shots, one drawable child each, one or two uploaded per paint with <code>texElementSubImage2D()</code></td><td>works</td><td>Live check: the card's background at 1.0 s, frame 60 of the clip at 2.3 s.</td></tr>
<tr><td>Transition where two shots overlap: fade, wipe, and the <code>ripple</code>, <code>pixelate</code> and <code>swirl</code> GLSL of <code>lib/live-transition.js</code></td><td>works</td><td>The three borrowed shaders are used as they are, with <code>transition</code> renamed. Each starts on the first shot and ends on the second. In the middle 53 to 98 % of the picture differs from either shot.</td></tr>
<tr><td>Editing a title card on the WebGL canvas (<code>contenteditable="plaintext-only"</code>)</td><td>works (script, touch)</td><td>A tap on the heading put the caret in it and typing changed the text and the row in the list. The shot in front gets its hit box with <code>updateElementGeometry()</code>. The others are moved off the canvas.</td></tr>
<tr><td>A card's motion as CSS functions of one custom property (<code>--t</code>)</td><td>works</td><td><code>letter-spacing</code>, <code>opacity</code>, <code>scaleX</code> and <code>translate</code> computed from <code>--t</code> with <code>calc()</code>, <code>min()</code> and <code>clamp()</code>. The picture uploaded in a paint has the value set before that paint.</td></tr>
<tr><td><code>exportFrames()</code> over several videos and cards</td><td>works</td><td>It is given an object with <code>currentTime</code>, <code>pause()</code>, <code>play()</code> and a <code>seeked</code> event that seeks every video on the timeline. 36 frames across a transition: the first is the card, the last holds frame 57 of the clip, as asked. The whole default timeline: 306 frames, VP9, 107 ms per frame at 928×522 and 138 ms at 998×748 (script).</td></tr>
<tr><td>Sound in the export</td><td>not built</td><td><code>exportFrames()</code> takes one <code>AudioBuffer</code> for one video. A timeline needs the tracks mixed first.</td></tr></tbody></table>
<h3>Cinema screen with a <code>PannerNode</code> (22.2)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A <code>&lt;video controls&gt;</code> on a quad in perspective, drawn with the page's WebGL context</td><td>works</td><td>The clip-space matrix of the quad, multiplied into CSS pixels, goes to <code>updateElementGeometry()</code> as a <code>DOMMatrix</code> with a perspective row.</td></tr>
<tr><td>Native controls on that quad</td><td>work with a mouse (script)</td><td>A click on the picture started playback. <code>elementFromPoint()</code> at the projected centre returns the video.</td></tr>
<tr><td>The same with touch</td><td>partly (script)</td><td>A tap on the picture shows the controls and does not start playback, as on a plain video. The play button itself is small on a phone, so the page has a Play button under the canvas as well. The video element is 400 CSS pixels wide to make its controls larger on the screen.</td></tr>
<tr><td>Seat buttons on a floor quad</td><td>work (script, mouse and touch)</td><td>A tap on the projected button chose the seat. <code>getBoundingClientRect()</code> of a button returns its projected place.</td></tr>
<tr><td><code>createMediaElementSource(video)</code> into a <code>PannerNode</code> at the screen, <code>AudioListener</code> at the seat</td><td>works</td><td>Offline render, equal-power panning: a seat 3 m to the left hears 0.09 left and 0.15 right, a seat to the right the reverse, the front row 0.24 and the back row 0.10 in each ear. With the head turned 90° to the right: 0.17 left, 0.00 right.</td></tr>
<tr><td>The same graph live with <code>panningModel: 'HRTF'</code></td><td>runs (script)</td><td>The two <code>AnalyserNode</code> levels moved the way the offline render says when the seat and the head changed. The headless browser has no sound output.</td></tr>
<tr><td>three.js for the room</td><td>not used</td><td>The site allows one WebGL context per page. The room is three quads in the page's own context, so the three scenes share it. <code>/three-form/</code> remains the three.js version of HTML on meshes.</td></tr></tbody></table>
<h3>A shader on the timeline only (22.4)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Finding the timeline: <code>::-webkit-media-controls-timeline</code> gets a magenta background for one paint, the picture goes into a spare texture, its bottom quarter is read once</td><td>works</td><td>The box is the full width of the player and 24 CSS pixels high at the bottom. The track is drawn at the top edge of that box, 16 px in from each side.</td></tr>
<tr><td>Replacing only the strip</td><td>works</td><td>With each skin on and off, nothing more than three strip heights above the strip changes, and 89 to 96 % of the strip does.</td></tr>
<tr><td>Input on the skinned strip</td><td>works (script)</td><td>A click at 75 % of the width seeked to 76 % (mouse, 928 px wide) and 78 % (touch, 380 px wide). The native thumb travels between points 22 px inside the box, so the shader draws its playhead with that inset.</td></tr>
<tr><td>Keeping the timeline during playback</td><td>works</td><td><code>opacity: 1 !important</code> on the panel and the timeline, as on <code>/player-parts/</code>. The box found last is kept while the controls are not painted.</td></tr></tbody></table>
<h3>Wide-gamut and HDR video in a Display P3 canvas (22.3)</h3>
<p>The test clips are <code>video-lab/wide.webm</code> (VP9 profile 0, tagged BT.2020 primaries with the BT.709 transfer function: bars of red, green, blue and white) and <code>video-lab/hdr.webm</code> (VP9 profile 2, 10 bit, BT.2020 and PQ: a grey ramp). Pixels are read from a <code>drawImage()</code> copy in a plain canvas with the same colour space, with <code>getImageData({ colorSpace: 'display-p3' })</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>BT.2020 video, <code>drawElementImage()</code> into a 2D canvas with <code>colorSpace: 'display-p3'</code></td><td>colours outside sRGB are kept</td><td>The red bar reads (255, 0, 13) as Display P3. From an sRGB canvas it reads (234, 51, 35), which is sRGB red. 42.9 % of the P3 canvas is outside sRGB and none of the sRGB canvas.</td></tr>
<tr><td>The same through <code>drawImage(video)</code></td><td>same values</td><td>Measured before the page was written: (118, 0, 3) and (119, 21, 12) on a dark band of the bar by both routes.</td></tr>
<tr><td><code>color(display-p3 1 0 0)</code> in the same element</td><td>(255, 0, 0) in the P3 canvas, (234, 51, 35) from the sRGB canvas</td><td></td></tr>
<tr><td>HDR10 (PQ) video in a <code>float16</code> Display P3 canvas</td><td>at most 1.0</td><td>The canvas multiplies its picture by 0.25 after drawing and the copy reads 64 at the brightest part. So no float readback is needed to see that the value was 1.0. The live check is marked as expected to fail.</td></tr>
<tr><td>HDR10 video in an 8-bit canvas</td><td>tone-mapped</td><td>White reads 255.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>Reported from Chrome on a Mac on 2026-11-21 (WebGPU on screen, <code>bgra8unorm</code>, frame through <code>copyExternalImageToTexture(video)</code>): the meld lens became a square while the tab had focus. A hovered or focused play button has a dark disc and a focus ring behind its glyph, and the shader took the glyph's shape from alpha. It now takes it from brightness: the glyph is white. A live check gives the button a dark background and compares the lens (41 % of it changed before, 6 % after). <code>/player-fx/</code> had the same alpha test in its GLSL and has the same fix.</li>
<li>The same report showed the guard's <code>timed-readback</code> warning: the parts were measured again on every <code>pointerenter</code>, <code>pointerdown</code>, play and pause, each a <code>mapAsync()</code>. They are now measured once per canvas size and once after the video loads.</li></ul>
<ul><li>A check that compared the canvas just before and just after a transition failed when the two times fell in different video frames. The fixture's clip starts half a frame into its file, so no seek lands on a frame boundary.</li>
<li><code>swirl</code> and <code>pixelate</code> are continuous at the ends of a transition but change fast there: 0.7 % before the end, <code>swirl</code> still turns the picture by 0.15 radians. The check reads half a millisecond from each end.</li>
<li>A title card at <code>--t</code> 0 has no visible text, so a tap finds nothing to edit. The editor starts stopped at 1.0 s.</li>
<li>The magenta probe does not cover the whole timeline box: the track and the thumb are painted over it. The bounding box of the magenta pixels is still the element's box.</li>
<li>A listener that faced the centre of the screen from every seat heard no difference between a left and a right seat. Seats face the far wall.</li>
<li>A canvas <code>getBoundingClientRect()</code> in a test only helps if the point is in the viewport: <code>elementFromPoint()</code> returns null below the fold. The check canvas is fixed in a corner of the window.</li>
<li>The native controls of a small video (256×144) fill its lower half, so the play button starts at half height.</li></ul>
<h3>Not verified</h3>
<ul><li>WebGPU on screen on the phone, and the speed. Reported working on Chrome on a Mac on 2026-11-21: the pass presents to the canvas and <code>copyExternalImageToTexture(video)</code> gives the frame. To verify on the phone, open <code>/video-lab/</code>, scroll to "The player shader in WebGPU" and read the line under the canvas, then run the live checks and read the last row.</li>
<li>A wide-gamut screen: that the Display P3 canvas looks more saturated than the sRGB one. The caption under the right canvas says what gamut the screen reports.</li>
<li>An HDR screen: whether the PQ clip keeps values above 1.0 in the float16 canvas there. The ninth live check reports the value.</li>
<li>The sound through speakers or headphones, and whether <code>AudioContext</code> starts from a tap on the play button drawn on the screen on Android.</li>
<li>Typing on a title card with the Android keyboard, and whether the keyboard moves the page.</li>
<li>Export speed and the largest size the encoder accepts on the phone.</li>
<li>Hardware video decoding with three decoders on one page (two clips in the editor and one in the scene last used).</li></ul>
<h3>Open ideas</h3>
<ul><li>Sound in the export: decode each clip's track, mix them on the timeline with an <code>OfflineAudioContext</code>, and give the result to the muxer.</li>
<li>Trim handles and a thumbnail strip for each clip, drawn by the same canvas.</li>
<li>A transition picker that previews each shader on the two shots it joins.</li>
<li>The cinema with <code>HTMLTexture</code> in three.js once the site has a way to share one context between three.js and <code>ElementGL</code>.</li>
<li>22.6 of the backlog (animated images as canvas children) is not part of this page.</li></ul>
<p><a href="https://html-in-canvas.page/video-lab/">Open Video lab: title editor, cinema sound, wide gamut, timeline skin, WebGPU player</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Video as a material for editable text</title>
<link>https://html-in-canvas.page/video-text/</link>
<guid isPermaLink="true">https://html-in-canvas.page/video-text/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>texElementSubImage2D</category>
<category>texImage2D(video)</category>
<category>contenteditable</category>
<category>mix-blend-mode</category>
<category>WebGL 2</category>
<description>Editable, wrapped HTML text and a playing video as two inputs to one shader. The video fills, pushes, plates and weights the glyphs. The same fill is built with CSS blending, an SVG clip path and a 2D canvas for comparison.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/video-text/"><img src="https://html-in-canvas.page/video-text/social.jpg" width="1200" height="630" alt="The page &quot;Video as a material for editable text&quot;"></a></p>
<p><strong>Question:</strong> Can live DOM text be filled, lit or displaced by a playing video in a shader, and which of those can plain CSS already do with no canvas?</p>
<p><strong>Short answer:</strong> Yes. Fill and punch can also be done with mix-blend-mode or a 2D canvas. Displace, chrome, mosaic and weight need the pixels of both the text and the video, which only the canvas gives.</p>
<p>
The large text below is two editable HTML elements in one canvas. A shader takes their picture as one texture and a video frame as a second.
Type in the text, select it, and pick an effect. Under the code listing, the same fill is built three times with CSS and no shader.
</p>
<h3>How it works</h3>
<ul>
<li>The text element fills the canvas. Its font size is a fraction of <code>canvas.clientWidth</code>, so a narrower canvas wraps the text again. The browser does the wrapping.</li>
<li>The text is styled white on a clear background. In the shader, coverage is the smallest of the red, green and blue channels of the premultiplied text texture. A white glyph pixel gives 1, a clear pixel gives 0, and an antialiased edge gives its alpha.</li>
<li>A pixel that has alpha but isn't white isn't a glyph. That's the selection highlight, the caret, the focus ring or a colour emoji. The shader draws those over the effect in their own colour at 60% strength.</li>
<li>The video isn't a child of the canvas. <code>texImage2D(video)</code>, <code>copyExternalImageToTexture()</code> or <code>drawImage(video)</code> reads its current frame. <code>requestVideoFrameCallback()</code> asks for one paint per video frame. Typing, the caret and selection changes raise <code>paint</code> with no request.</li>
<li>WebGL and WebGPU don't tell the browser where the element is drawn. The page calls <code>updateElementGeometry()</code> with an identity matrix after each resize, so taps and the caret go to the text as it is laid out.</li>
<li>The 2D route has no shader. It draws the text, then draws the video with <code>globalCompositeOperation = 'source-in'</code> (fill) or <code>'source-out'</code> (punch). It builds those two effects only.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 headless with software rendering and software video decoding, 2026-11-21. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: editable DOM text as a shader input next to a video frame.</strong> The text stays editable, selectable and wrapped by the browser in every route. Six effects are built. A pixel inside a glyph differed from the video pixel by 1 of 255.</li>
<li><strong>Works with CSS and no canvas: fill and punch.</strong> <code>mix-blend-mode: multiply</code> or <code>screen</code> on text over a video gives both, with editable HTML text. An SVG <code>&lt;clipPath&gt;</code> or <code>&lt;mask&gt;</code> gives the fill for SVG text and shapes only.</li>
<li><strong>Works: the CSS blend inside a drawable element.</strong> When the video and the blended text are both inside the drawn element, the blend is in its picture.</li>
<li><strong>Works in 2D only: the blend mode of the drawn element itself.</strong> <code>drawElementImage()</code> applied <code>mix-blend-mode: multiply</code> on the element against the pixels the canvas already held. <code>texElementSubImage2D()</code> gave the unblended picture, so a shader doesn't see the blend.</li>
<li><strong>Works: three ways to fill text with video in a 2D canvas.</strong> <code>source-in</code>, <code>globalCompositeOperation = 'multiply'</code>, and the element's own blend mode. Mean difference from the shader fill: 1.5 of 255.</li>
<li><strong>Limit: <code>background-clip: text</code> can't use a video.</strong> Chromium has no <code>element()</code> and no <code>-webkit-canvas()</code> image. <code>paint()</code> parses, but a paint worklet draws CSS image values only (inferred from its interface, not measured).</li>
<li><strong>Needs the canvas: displace, chrome, mosaic and weight.</strong> Each one reads the text's pixels and the video's pixels at different places and computes a new pixel. CSS blending and clipping combine the two pictures at the same place only. The 2D route can't build them without a per-pixel loop in script.</li>
<li><strong>Selection and caret are in the text texture.</strong> A route that uses alpha as coverage (2D <code>source-in</code>) turns the selection highlight and the caret into video. The shader keys on white, so it draws glyphs with the effect and the highlight and caret in their own colours.</li>
<li><strong>Timing: a video beside the canvas raises no paint.</strong> 0 paints a second, against 30 with the video inside the drawn element. <code>requestVideoFrameCallback()</code> supplies them. With the page idle, the frame from <code>texImage2D(video)</code> was the frame the callback reported in 26 of 28 paints. With a second canvas drawing in software at the same time it was 2 to 6 frames newer.</li>
<li><strong>Limit: a WebGL canvas needs <code>updateElementGeometry()</code>.</strong> Before the call, <code>elementFromPoint()</code> at a drawn letter returned the canvas and no caret position. After it, the paragraph and the right offset.</li>
<li><strong>WebGPU: built, compared off screen only.</strong> On the software adapter the six WGSL effects matched WebGL exactly. That adapter refused <code>copyExternalImageToTexture(video)</code> and <code>importExternalTexture(video)</code>, so the frame went through a 2D canvas.</li>
<li><strong>Not verified here:</strong> the WebGPU route on screen and a video frame straight into a GPU texture, a hardware-decoded frame through <code>texImage2D(video)</code> on Android, touch selection handles and the on-screen keyboard on the drawn text, and the frame rate on a phone.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-text.md">findings/video-text.md</a> in the repository.</p>
<p>Chromium 157 headless (C157), software rendering and software video decoding, 2026-11-21. Phone emulation at 412 px wide. All results are measured by the page's live checks unless a row says "script" (a Playwright script run against the page) or "inferred". The clip is <code>/media/clip.webm</code>, loaded as a blob URL.</p>
<p>The question: can live DOM text (editable, selectable, wrapped by the browser) be filled, lit or displaced by a playing video in a shader, and which of those can plain CSS do with no canvas.</p>
<h3>The demo</h3>
<p>Two <code>contenteditable</code> elements in one <code>drawable</code> child of a canvas. A <code>&lt;video hidden&gt;</code> beside the canvas. One fragment shader reads the text as an element texture and the video frame as a second texture. Six effects: fill, displace, chrome, punch, mosaic, weight. Three routes, chosen through <code>shared/backend.js</code>: WebGPU, WebGL 2, 2D canvas.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Text texture from <code>texElementSubImage2D()</code> for a white letter on a clear background</td><td>16.1% white and opaque, 83.0% clear, 0.9% antialiased edge, 0 coloured pixels</td><td>Premultiplied. Antialiasing on a clear background is greyscale, so the smallest of r, g, b equals alpha on every glyph pixel.</td></tr>
<tr><td>Fill in the shader: pixel inside a glyph against <code>drawImage(video)</code> at the same place</td><td>largest difference 1 of 255 over 111 points</td><td>533 points outside the glyph equal the background exactly.</td></tr>
<tr><td>Typing, caret and selection on the drawn text, WebGL route</td><td>work (script)</td><td>Clicked in the text, typed, extended a selection with Shift and arrow keys. The text reflows when the canvas width changes: the font size is a fraction of <code>canvas.clientWidth</code>.</td></tr>
<tr><td>Edit the DOM text, no <code>requestPaint()</code></td><td><code>paint</code> came 21 ms later with the new picture</td><td>222 ms when the visible demo was also drawing in software.</td></tr>
<tr><td><code>elementFromPoint()</code> and <code>caretPositionFromPoint()</code> at a drawn letter on a new WebGL canvas</td><td>before <code>updateElementGeometry()</code>: the canvas, no caret. After, with an identity matrix: the paragraph, offset 3 of "CARET"</td><td></td></tr>
<tr><td>Caret in the picture</td><td>drawn, and it blinks with no <code>requestPaint()</code> (script)</td><td>6 <code>paint</code> events in 3 s with the video paused. In WebGL about 11 pixels in the caret colour come and go.</td></tr>
<tr><td>Selection highlight in the text texture</td><td>premultiplied 0,91,255,115 for CSS <code>rgb(0 90 255 / 0.45)</code></td><td>The glyph pixels inside the selection stay white.</td></tr>
<tr><td>How the shader treats what is not a glyph</td><td>coverage is <code>min(r, g, b)</code> of the premultiplied texel. <code>alpha - coverage</code> is "other" and is drawn over the effect in its own colour at 60%</td><td>Other is the highlight, the caret, the focus ring and colour emoji. At one highlight pixel WebGL drew 8,64,166 where the video was 10,130,81.</td></tr>
<tr><td>The same pixel in the 2D <code>source-in</code> route</td><td>11,66,47: the video at the highlight's alpha</td><td><code>source-in</code> reads alpha only, so a selection is a block of video and the caret is a bar of video.</td></tr>
<tr><td>2D route: <code>drawElementImage()</code> then <code>drawImage(video)</code> with <code>source-in</code></td><td>same fill as the shader, mean difference 1.46 of 255, largest 232</td><td>The large values are single edge pixels. <code>source-out</code> gives punch.</td></tr>
<tr><td>2D route: displace, chrome, mosaic, weight</td><td>not built</td><td>They read the text and the video at different places. That needs a per-pixel loop in script on a 2D canvas. The menu disables them on that route.</td></tr>
<tr><td>Displace in the shader</td><td>818 of 14400 sampled pixels lit where the text texture has no coverage</td><td>The video's brightness and colour moved those glyph pixels.</td></tr>
<tr><td>Switching route</td><td>works (script)</td><td>A canvas keeps its first context type, so the page makes a new canvas, moves the text element into it and removes the old canvas. One GPU context is in the document at a time.</td></tr>
<tr><td>Camera as the video</td><td>works (script)</td><td>Chromium's fake camera through <code>srcObject</code>. Started from the menu only.</td></tr></tbody></table>
<h3>Timing</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>paint</code> events with the video beside the canvas, no <code>requestPaint()</code></td><td>0 a second</td><td><code>texImage2D(video)</code> does not invalidate the canvas. The page calls <code>requestPaint()</code> from <code>requestVideoFrameCallback()</code>.</td></tr>
<tr><td>The same video as a child of the drawable element, frame moved out with <code>object-position: -9999px 0</code></td><td>30 a second</td><td><code>texImage2D()</code> of that child still gives the frame. With <code>opacity: 0</code> on the child: 30 a second.</td></tr>
<tr><td>Frame from <code>texImage2D(video)</code> minus the frame number written into the DOM by <code>requestVideoFrameCallback()</code>, read from one paint, demo off screen</td><td>0 in 26 of 28 paints, +1 in 2. A later run: 0 in 28 of 28</td><td>28 to 29 callbacks a second. The same with the video outside the document and with it in the document.</td></tr>
<tr><td>The same while the visible demo was also drawing in software</td><td>+2 to +6 frames</td><td>7 to 11 callbacks a second. The paint handler ran that long after the callback. This row fails on the page when the median is above 1.</td></tr></tbody></table>
<h3>CSS and SVG with no shader</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>mix-blend-mode: multiply</code>, white text on a black box over a <code>&lt;video&gt;</code>, plain DOM</td><td>fill, with editable HTML text</td><td>Visual only on the page (first box). <code>screen</code> with black text on white gives the punch.</td></tr>
<tr><td>The same markup inside one drawable element, <code>drawElementImage()</code></td><td>blend kept: block pixel 173,246,7 equals the video, outside 0,0,0</td><td>The video and the text are both in the element's picture.</td></tr>
<tr><td><code>mix-blend-mode: multiply</code> on the drawn element itself, video drawn first with <code>drawImage()</code></td><td>the blend reaches the 2D canvas: block 173,246,7, outside 0,0,0. Without the property: block 255,255,255</td><td>Not expected. <code>drawElementImage()</code> composites the element with its own blend mode against what the canvas holds.</td></tr>
<tr><td>The same element through <code>texElementSubImage2D()</code></td><td>unblended: block 255,255,255,255, outside 0,0,0,255</td><td>A shader does not see the blend mode.</td></tr>
<tr><td><code>globalCompositeOperation = 'multiply'</code> then <code>drawElementImage()</code></td><td>fill</td><td>A second 2D way beside <code>source-in</code>.</td></tr>
<tr><td><code>background-clip: text</code> with the video as the background image</td><td>no route</td><td><code>CSS.supports()</code>: <code>element()</code> no, <code>-moz-element()</code> no, <code>-webkit-canvas()</code> no, <code>paint()</code> parses. A paint worklet draws CSS image values only (inferred from its interface, not run).</td></tr>
<tr><td>HTML <code>&lt;video&gt;</code> with <code>clip-path: url(#…)</code> to an SVG <code>&lt;clipPath&gt;</code> holding <code>&lt;rect&gt;</code> and <code>&lt;text&gt;</code>, as a drawable child</td><td>works: rect pixel equals the video, alpha 0 outside, 1474 video pixels in the shape of the SVG text</td><td>SVG text only: no wrapping, no editing. <code>clip-path</code> with <code>path()</code> or <code>polygon()</code> cannot follow text.</td></tr>
<tr><td><code>&lt;video&gt;</code> in a <code>&lt;foreignObject&gt;</code> with an SVG <code>&lt;mask&gt;</code>, as a drawable child</td><td>works: rect pixel equals the video, alpha 0 outside</td><td></td></tr></tbody></table>
<p>Which effects need the canvas: fill and punch do not. Displace, chrome, mosaic and weight do, because each output pixel is computed from text pixels and video pixels at other places. CSS blending, clipping and masking combine two pictures at the same place only.</p>
<h3>WebGPU</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>WGSL version of the shader against the GLSL one, off screen, software adapter (<code>--enable-unsafe-webgpu --enable-unsafe-swiftshader</code>)</td><td>mean difference 0.00 of 255 for all six effects</td><td><code>drawElementImageToTexture()</code> for the text, render into a texture, read back.</td></tr>
<tr><td><code>copyExternalImageToTexture({ source: video })</code> on that adapter</td><td>throws "Failed to copy content from video element"</td><td>Same for a <code>VideoFrame</code> made from the video, paused or playing, in or out of the document (script).</td></tr>
<tr><td><code>importExternalTexture({ source: video })</code> on that adapter</td><td>throws "Failed to import texture from video"</td><td></td></tr>
<tr><td><code>drawImage(video)</code> into a 2D <code>OffscreenCanvas</code>, then <code>copyExternalImageToTexture(canvas)</code></td><td>works</td><td>The route falls back to this when the direct copy throws. <code>createImageBitmap(video)</code> also works but is asynchronous.</td></tr>
<tr><td>Default headless launch</td><td>no adapter</td><td>The WebGPU check row fails with "not run".</td></tr></tbody></table>
<h3>Contexts</h3>
<p>The page makes 1 WebGL context on load. During the checks the largest number alive is 3: the demo, one fixture canvas shared by every WebGL check, and one new canvas for the hit-test check, which must never have been given a geometry. The jank guard reports <code>gl 1/0</code> on load and <code>gl 3/0</code> with checks. The visible demo does no readback except one 24 px copy in the last check.</p>
<h3>Things that bit</h3>
<ul><li>A listener added after the page's <code>paint</code> listener does not run before code that awaits a promise resolved in the first listener. A microtask checkpoint runs between listeners. A value "captured at paint time" by the second listener was one paint old.</li>
<li>The frame-sync numbers depend on what else the page draws. With the demo on screen in software rendering, callbacks dropped to 8 a second and the lag rose to 6 frames. Scrolled to the checks, the lag was 0.</li>
<li><code>updateElementGeometry()</code> stays in force on an element. A reused fixture reported a working hit test "before" the call. The hit-test check uses a new canvas.</li>
<li>A drawing error inside the <code>paint</code> handler left a check waiting for a readback. The wait now reports the error text.</li>
<li>A software WebGPU adapter refuses video sources. Without the 2D canvas fallback the WGSL comparison could not run.</li></ul>
<h3>Not verified</h3>
<ul><li>The WebGPU route on screen. The page's "Drawn with" menu offers it where <code>webgpu()</code> gives a device. The WebGPU check row compares it with WebGL off screen on the device.</li>
<li><code>copyExternalImageToTexture(video)</code> and <code>importExternalTexture(video)</code> on a hardware adapter. The WebGPU check row reports both. The shader uses a plain <code>texture_2d</code>, so an external texture is not used for drawing.</li>
<li>A hardware-decoded frame through <code>texImage2D(video)</code> on Android. The second check row answers it.</li>
<li>Frame lag and paint rate on a phone. The fourth and sixth check rows report them.</li>
<li>Touch selection handles, long-press selection and the on-screen keyboard on the drawn text. Needs a hand on the phone.</li>
<li>The camera on a real device.</li>
<li>Whether a paint worklet can be given a video frame. Not run.</li>
<li>Whether <code>drawElementImage()</code> applying the element's <code>mix-blend-mode</code> is intended. Checked for <code>multiply</code> only.</li></ul>
<h3>Open ideas</h3>
<ul><li>Per-glyph effects from real glyph boxes: <code>Range.getClientRects()</code> per character as a uniform array or a small data texture, so each letter gets its own video crop or delay.</li>
<li>A signed distance field made from the text texture once per edit, for wide outlines and bevels without 68 texture reads per pixel.</li>
<li>The video inside the drawable element at <code>opacity: 0</code>, as a way to get one paint per frame with no <code>requestVideoFrameCallback()</code> loop.</li>
<li>The same shader with the page's own scrolled content as the material in place of the video.</li></ul>
<p><a href="https://html-in-canvas.page/video-text/">Open Video as a material for editable text</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A &lt;video&gt; element inside a canvas</title>
<link>https://html-in-canvas.page/video/</link>
<guid isPermaLink="true">https://html-in-canvas.page/video/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>&lt;video&gt;</category>
<category>::cue</category>
<category>requestVideoFrameCallback</category>
<category>EME</category>
<description>A playing video with its native controls and captions, drawn through a fragment shader. The controls still work. Cross-origin and encrypted video are left out of the picture.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/video/"><img src="https://html-in-canvas.page/video/social.jpg" width="1200" height="630" alt="The page &quot;A &lt;video&gt; element inside a canvas&quot;"></a></p>
<p><strong>Question:</strong> Does a playing <code>&lt;video&gt;</code> with native controls and captions draw into a canvas, frame by frame, and do its controls still work under a shader?</p>
<p><strong>Short answer:</strong> Frames, controls and <code>::cue</code> captions are drawn, and <code>paint</code> fires for each video frame. Cross-origin video without CORS and encrypted video are left out.</p>
<p>
The player below is a <code>&lt;div fx&gt;</code> that holds a <code>&lt;video controls&gt;</code> with a captions track, and an HTML
label with a button. All of it is drawn into a canvas through a fragment shader. Use the video's own controls and the button, then
change the source and the effect.
</p>
<h3>How it works</h3>
<ul>
<li>A <code>&lt;video&gt;</code> is drawn like any other element. The picture taken by <code>drawElementImage()</code>, <code>texElementSubImage2D()</code> or <code>drawElementImageToTexture()</code> holds the current frame, the native controls and the captions.</li>
<li>No render loop is needed for the video. The canvas gets a <code>paint</code> event for every new video frame.</li>
<li>The native controls are part of the element, so hit testing reaches them wherever the element's geometry is. The <code>fx</code> library leaves the element where layout put it, so the play button and the timeline work under the shader.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157 with software video decoding and software rendering. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: frames, controls, captions.</strong> A playing video draws its current frame. Captions from a <code>&lt;track&gt;</code> are drawn with their <code>::cue</code> style. The controls are drawn when the element shows them.</li>
<li><strong>Works: lazy loading counts a canvas child as near the viewport.</strong> A <code>&lt;video loading="lazy"&gt;</code> inside a canvas that is in the window loads and is drawn.</li>
<li><strong>Works: a frame drawn through a canvas counts as rendered.</strong> A video in an iframe with <code>allow="media-playback-while-not-visible 'none'"</code> keeps playing when the iframe is a canvas child. Reading the canvas back after a repaint of that iframe crashed the tab in the check, so the check reads only the video's clock. Smaller cases didn't crash and the cause isn't known.</li>
<li><strong>Works: the canvas follows the video clock.</strong> <code>paint</code> fired 30 times a second for a 30 fps clip with no call to <code>requestPaint()</code>. The frame in the canvas was the frame <code>requestVideoFrameCallback()</code> had just reported in 40 of 40 samples, and after <code>seeked</code> it was the frame asked for in 10 of 10.</li>
<li><strong>Works: input.</strong> Play, the timeline, mute and the overflow menu were pressed on the drawn controls, and the menu is drawn in the canvas too. A click on the timeline also seeks with the element drawn at half size in another place. Fullscreen and Picture-in-Picture were entered from script.</li>
<li><strong>Works: alpha.</strong> A VP9 clip with an alpha channel is drawn with it, so the content behind the video shows.</li>
<li><strong>Works: a camera stream</strong> in <code>srcObject</code> draws like a file (tested with Chromium's fake camera).</li>
<li><strong>Left out: cross-origin video without CORS.</strong> The video plays, but its pixels are missing from the element's picture and the area is clear. The canvas isn't tainted, so <code>toDataURL()</code> and <code>getImageData()</code> still work. With <code>crossorigin</code> on the element and a CORS header on the file it is drawn.</li>
<li><strong>Left out: encrypted video.</strong> A Clear Key clip plays in a plain element and is black in the canvas. <code>drawImage(video)</code> gives the same black frame. Widevine wasn't tested.</li>
<li><strong>Left out: a nested <code>drawable</code>.</strong> A video with its own <code>drawable</code> attribute inside a <code>drawable</code> parent is missing from the parent's picture. Draw it with its own call, or leave the attribute off.</li>
<li><strong>Picture-in-Picture empties the element.</strong> While the video is in a Picture-in-Picture window the element paints a black placeholder, the canvas shows that, and <code>paint</code> nearly stops (2 events in 500 ms).</li>
<li><strong>A canvas can play its own stream.</strong> A child <code>&lt;video&gt;</code> whose <code>srcObject</code> is the canvas's own <code>captureStream()</code> draws, and the picture repeats inside itself.</li>
<li><strong>Not verified here:</strong> hardware-decoded video on a phone, HDR video, and the WebGPU route on screen. The first four live checks answer the first on your device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/video-and-sound.md">findings/video-and-sound.md</a> in the repository.</p>
<h3>A <code>&lt;video&gt;</code> as a canvas child (<code>/video/</code>)</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Playing <code>&lt;video&gt;</code> inside a <code>drawable</code> element, <code>drawElementImage()</code></td><td>works</td><td>The current frame is in the element's picture.</td></tr>
<tr><td>Same element through <code>texElementSubImage2D()</code></td><td>works</td><td>Frame 77 was asked for and read back from the texture.</td></tr>
<tr><td><code>paint</code> events with no <code>requestPaint()</code></td><td>30 a second for a 30 fps clip</td><td>The video invalidates the canvas for each presented frame. No render loop is needed.</td></tr>
<tr><td><code>requestVideoFrameCallback()</code> then <code>requestPaint()</code></td><td>the canvas holds the reported frame, 40 of 40</td><td>The frame number in the picture equals <code>Math.round(metadata.mediaTime * 30)</code>.</td></tr>
<tr><td>Set <code>currentTime</code>, wait for <code>seeked</code>, <code>requestPaint()</code></td><td>the exact frame, 10 of 10</td><td>About 20 to 35 ms per seek and paint at 320×180. This is what frame-by-frame export uses.</td></tr>
<tr><td><code>&lt;track&gt;</code> captions with a <code>::cue</code> rule</td><td>drawn with the rule's colours</td><td>The cue box moves up when the controls are shown, as in a plain element.</td></tr>
<tr><td>Native controls</td><td>drawn when the element shows them</td><td>Hidden while playing with no hover, as usual.</td></tr>
<tr><td>Click on the drawn timeline, element drawn at half size 100 px away</td><td>seeks</td><td>The controls are part of the element, so they follow its hit-test geometry. Play, mute and the overflow menu were also pressed on the drawn controls under the shader, and the menu is drawn in the canvas. Fullscreen and Picture-in-Picture were entered from script.</td></tr>
<tr><td>VP9 clip with an alpha channel</td><td>alpha kept</td><td>The parent's background shows through.</td></tr>
<tr><td>Camera stream in <code>srcObject</code></td><td>works</td><td>Chromium's fake camera.</td></tr>
<tr><td><code>&lt;audio controls&gt;</code></td><td>drawn and usable</td><td></td></tr>
<tr><td>Child <code>&lt;video&gt;</code> playing the canvas's own <code>captureStream()</code></td><td>works</td><td>The picture repeats inside itself. No crash.</td></tr>
<tr><td><code>&lt;video drawable&gt;</code> inside a <code>drawable</code> parent</td><td>missing from the parent's picture</td><td>A nested <code>drawable</code> element is left out. Leave the attribute off, or draw the video with its own call.</td></tr>
<tr><td>Cross-origin video without CORS</td><td>left out, canvas not tainted</td><td>The video plays. Its area in the picture is clear. <code>toDataURL()</code> and <code>getImageData()</code> still work.</td></tr>
<tr><td>Cross-origin video with <code>crossorigin</code> and a CORS header</td><td>works</td><td></td></tr>
<tr><td>Clear Key encrypted video (EME)</td><td>black, canvas not tainted</td><td>Plays in a plain element. <code>drawImage(video)</code> gives the same black frame. Needed a WebM encryptor (<code>tools/media/encrypt-webm.mjs</code>): ffmpeg's <code>cenc</code> MP4 output was refused by Chromium's demuxer.</td></tr>
<tr><td>Video in a Picture-in-Picture window</td><td>the element paints a black placeholder</td><td><code>paint</code> drops to about 4 a second while it is away.</td></tr>
<tr><td>Fullscreen on the video</td><td>works</td><td>The element fills the screen as plain DOM and is drawn in the canvas again after exit.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/video/">Open A &lt;video&gt; element inside a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>View Transitions API with HTML-in-canvas</title>
<link>https://html-in-canvas.page/view-transitions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/view-transitions/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>startViewTransition</category>
<category>view-transition-name</category>
<category>@view-transition</category>
<description>A canvas that draws HTML inside startViewTransition(): which element can carry a name, a shader in place of the cross-fade, and a transition between two documents.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/view-transitions/"><img src="https://html-in-canvas.page/view-transitions/social.jpg" width="1200" height="630" alt="The page &quot;View Transitions API with HTML-in-canvas&quot;"></a></p>
<p><strong>Question:</strong> Does a canvas that draws HTML work with the View Transitions API, and can a shader replace the cross-fade?</p>
<p><strong>Short answer:</strong> A named canvas transitions as one live picture. A canvas child gets a group with no picture. Scoped transitions on the canvas or its children fail.</p>
<p>
Four experiments with <code>document.startViewTransition()</code>, <code>view-transition-name</code>, <code>element.startViewTransition()</code>
and cross-document transitions, each with a <code>&lt;canvas layoutsubtree&gt;</code> in the page.
The <a href="https://html-in-canvas.page/transitions/">live transitions page</a> doesn't use this API. This page does.
</p>
<h3>Findings</h3>
<ul>
<li><strong>A drawable canvas takes part in a view transition as one picture.</strong> Its snapshot is the canvas bitmap, HTML children included. The new snapshot is live, so the canvas can keep animating under <code>::view-transition-new()</code>.</li>
<li><strong>A canvas child can't be its own transition element.</strong> It gets a group with the right box and no picture. To move one element on its own, give it its own canvas and name that canvas.</li>
<li><strong>The old and new snapshots can't be read from script.</strong> There is no call that hands <code>::view-transition-old()</code> to a canvas or a shader. A shader transition has to keep both states itself (two live elements, or an <code>ElementImage</code> taken before the change) and switch the cross-fade off.</li>
<li><strong>Work that waits for a <code>paint</code> event must be done before <code>startViewTransition()</code>.</strong> The canvas gets no <code>paint</code> event while the update callback is pending.</li>
<li><strong>Element-scoped transitions (Chrome 147 and later).</strong> On an ancestor of the canvas they work as on the document. On the canvas they blank it, unless the canvas has <code>view-transition-name: none</code>: then it keeps drawing and the transition is an invisible set of group animations that the canvas can read. On a <code>drawable</code> child of the canvas they crash the renderer in Chromium 157.</li>
<li><strong>Inside a canvas-scoped transition, group sizes are right and group positions are all 0,0.</strong> In a document transition the group of a canvas child has the position that <code>drawElementImage()</code> gave it.</li>
<li><strong>Between documents</strong>, a named canvas cross-fades like any other element. An <code>ElementImage</code> can't follow the navigation, so a shader between two documents needs pixels: the old page stores a picture of its canvas, and the new page draws from that picture to its live content.</li>
</ul>
<h3>Not tried yet</h3>
<ul>
<li>Run the items of experiment 4 through a WebGL or WebGPU shader (trails, bending) with the same CSS clock.</li>
<li>Nested scopes: a scoped transition on the grid element with a canvas-scoped one inside it.</li>
<li>Navigation API <code>navigate</code> with <code>intercept()</code> and a shader transition for a single-page app's route changes.</li>
<li><code>view-transition-class</code> and nested groups (<code>view-transition-group: contain</code>) with one canvas per list item.</li>
<li>A page-wide shader: put the whole page in one canvas, so that a transition between any two states is drawn by the canvas and the View Transitions API is only used for timing.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/motion.md">findings/motion.md</a> in the repository.</p>
<h3>View Transitions API (<code>/view-transitions/</code>)</h3>
<p>Tested in headless Chromium 157 with <code>document.startViewTransition()</code>, <code>element.startViewTransition()</code> and <code>@view-transition { navigation: auto }</code>.</p>
<table><thead><tr><th>Question</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A <code>&lt;canvas layoutsubtree&gt;</code> with a <code>view-transition-name</code> in a document transition</td><td>works</td><td>The old snapshot is the canvas bitmap, HTML children included. The new snapshot is live: the canvas keeps getting <code>paint</code> events and a clock inside it keeps counting while the group moves and resizes.</td></tr>
<tr><td><code>view-transition-name</code> on a child of the canvas</td><td>group only, no picture</td><td><code>::view-transition-group(name)</code> exists and animates between the boxes that <code>drawElementImage()</code> (or <code>updateElementGeometry()</code>) gave the child. Both snapshots are empty. To move one element on its own, give it its own canvas and name the canvas.</td></tr>
<tr><td>A shader in place of the cross-fade</td><td>works</td><td><code>::view-transition-old(name) { display: none }</code> and <code>::view-transition-new(name) { animation: none }</code> leave the live canvas showing. The view transition moves the box and <code>&lt;live-transition&gt;</code> draws the change. <code>begin()</code> must finish before <code>startViewTransition()</code>: no <code>paint</code> event arrives while the update callback is pending.</td></tr>
<tr><td>Read <code>::view-transition-old()</code> into a canvas or texture</td><td>not possible</td><td><code>ViewTransition</code> has no call that returns pixels. A shader transition keeps its own copy of the old state.</td></tr>
<tr><td><code>element.startViewTransition()</code> on an ancestor of the canvas</td><td>works</td><td>Same result as on the document. The rest of the page stays interactive.</td></tr>
<tr><td><code>element.startViewTransition()</code> on the canvas itself</td><td>canvas is blank during the transition</td><td>A scope takes part in its own transition as <code>view-transition-name: root</code>. The pseudo-elements that would show its snapshot are inside the canvas, which renders none of its contents.</td></tr>
<tr><td>The same, with <code>view-transition-name: none</code> on the canvas</td><td>works, shows nothing by itself</td><td>The canvas keeps drawing and getting <code>paint</code> events. Named descendants get groups that are never shown. <code>vt.transitionRoot</code> is the canvas.</td></tr>
<tr><td>Read those hidden groups as a clock and draw the move in the canvas</td><td>works</td><td>Replace the group keyframes with one that animates a registered custom property (<code>--vt-p</code>) from 0 to 1 and read it with <code>getComputedStyle(canvas, '::view-transition-group(name)')</code>. CSS keeps control of duration, easing and per-item delay. The canvas draws each item with the nine-argument <code>drawElementImage()</code> and can add an arc, a turn and a shadow. The page stays interactive and other scoped transitions run at the same time.</td></tr>
<tr><td>Position of a group inside a canvas-scoped transition</td><td>wrong</td><td>Width and height are right. The transform is 0,0 for every group, so positions have to be measured with <code>offsetLeft</code> and <code>offsetTop</code> before and after the change. In a document transition the group of a canvas child has the right position.</td></tr>
<tr><td>Flow layout of direct canvas children</td><td>no</td><td>Each <code>drawable</code> child is laid out alone at the canvas origin. Put a grid or flex container in as one <code>drawable</code> child and name its children.</td></tr>
<tr><td><code>element.startViewTransition()</code> on a <code>drawable</code> child of <code>&lt;canvas content="drawable"&gt;</code></td><td>renderer crash</td><td>Crashes with or without <code>layoutsubtree</code>, with or without a draw, and with <code>view-transition-name: none</code> on the child. A child without the <code>drawable</code> attribute does not crash. A canvas without <code>content="drawable"</code> rejects with "Unsupported layout or style". Reproduction: <code>/view-transitions/crash.html</code>.</td></tr>
<tr><td>Cross-document transition with a named canvas on both pages</td><td>works</td><td>The canvas cross-fades and morphs like an image. <code>pagereveal</code> can fire before a module script runs, so listen for it in a classic script.</td></tr>
<tr><td>A shader between two documents</td><td>works with pixels</td><td>An <code>ElementImage</code> cannot follow a navigation. The old page stores a WebP of its canvas in <code>sessionStorage</code> before navigating. The new page inserts it as the first state of a <code>&lt;live-transition&gt;</code> and burns to the real content. The old snapshot stays visible underneath until the canvas has drawn. When the two boxes have different shapes the stored picture is stretched.</td></tr></tbody></table>
<p>Element-scoped view transitions shipped in Chrome 147 (developer testing from 140). References: https://developer.chrome.com/docs/css-ui/view-transitions/element-scoped-view-transitions, https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API/Using_element-scoped, https://drafts.csswg.org/css-view-transitions-2/.</p>
<p>Not tried yet: Navigation API <code>intercept()</code> with a shader for single-page route changes; the experiments below on WebGPU.</p>
<p><a href="https://html-in-canvas.page/view-transitions/">Open View Transitions API with HTML-in-canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Speak a label to press a control</title>
<link>https://html-in-canvas.page/voice/</link>
<guid isPermaLink="true">https://html-in-canvas.page/voice/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>SpeechRecognition</category>
<category>phrases</category>
<category>Highlight</category>
<category>fx</category>
<description>A panel of switches drawn through a shader. Say a name on it and that control is clicked, a ring spreads from it and the transcript highlights each word. The names of the controls drawn now are the phrases given to speech recognition.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/voice/"><img src="https://html-in-canvas.page/voice/social.jpg" width="1200" height="630" alt="The page &quot;Speak a label to press a control&quot;"></a></p>
<p><strong>Question:</strong> Can speech recognition press controls that a shader draws, using only the accessible names in the DOM, and does a word-by-word transcript highlight reach the canvas?</p>
<p><strong>Short answer:</strong> Names read from the DOM drive the matching and the phrase list, and custom highlights are in the element's picture. Recognition itself couldn't be run in the test browser.</p>
<p>
A panel of switches drawn through a shader. Press "Listen" and say a name on the panel, such as "lamp" or "studio", or type the words in
the box. The control is clicked, a ring spreads from it through the panel, and the transcript at the bottom highlights each word.
</p>
<h3>How it works</h3>
<p>
The panel is one drawable element, uploaded to a texture on every <code>paint</code> and drawn by a fragment shader
(<a href="https://html-in-canvas.page/lib/shader-fx.js"><code>fx</code></a>: WebGPU when it works, else WebGL). The names of the buttons that aren't hidden are read
from the DOM and given to <code>SpeechRecognition</code> as <code>phrases</code>, which makes the recogniser favour them. Words that come back
are compared with the same names, and a match calls <code>click()</code> on the button. Switching room hides one set of buttons and shows
the other, so the phrase list and the names that can be pressed change with what is drawn.
</p>
<p>
Words reach the panel through one function. The microphone, the text box and the live checks all call it, so the panel, the ring and the
transcript work in a browser with no speech recognition. The line under the demo says which parts of the Web Speech API this browser has.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The accessible names in the DOM are enough to drive a canvas UI by voice.</strong> The page doesn't keep a list of commands. It reads the names of the buttons that are drawn, and <code>click()</code> doesn't depend on where the shader puts the pixels.</li>
<li><strong>Custom highlights are in the element's picture.</strong> The live check compares the panel's texture with and without a highlight on one word of the transcript, and the pixels differ. The shader bends the highlighted word with the rest.</li>
<li><strong>A press from script can start the same ring as a pointer.</strong> <code>click()</code> fires no pointer event, so the page calls the surface's <code>poke(x, y)</code> with the control's layout position.</li>
<li><strong>Speech recognition couldn't be run in the test browser.</strong> Headless Chromium 157 has <code>SpeechRecognition</code>, <code>phrases</code>, <code>available()</code> and <code>install()</code>, and no microphone. Recognition, on-device processing and the effect of the phrase list aren't verified.</li>
<li><strong><code>SpeechRecognition.available({ langs: ['en-US'], processLocally: true })</code> crashes the tab in headless Chromium 157.</strong> The page therefore asks only after a tap on "Listen" or on the live checks button, and the check refuses to ask in an automated browser. Whether Chrome on a phone has the same crash isn't known.</li>
<li><strong><code>SpeechRecognitionResult</code> isn't a global in Chromium 157</strong>, so the timestamp check can't see <code>speechStartTime</code> there.</li>
<li><strong>Timestamps are per result, not per word</strong> (from the feature's description; not run). <code>speechStartTime</code> and <code>speechEndTime</code> (Chrome 159) are on <code>SpeechRecognitionResult</code>. The page spreads the words of a final result evenly between the two times. Before a result is final, each word has the time it arrived. "Replay the timing" plays the highlights back with those times.</li>
<li><strong>Not verified:</strong> everything that needs a microphone, on-device recognition on Android, whether <code>phrases</code> changes what is recognised, and WebGPU on screen.</li>
</ul>
<p><a href="https://html-in-canvas.page/voice/">Open Speak a label to press a control</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A WebAssembly loop that waits for the paint event</title>
<link>https://html-in-canvas.page/wasm-ui/</link>
<guid isPermaLink="true">https://html-in-canvas.page/wasm-ui/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebAssembly</category>
<category>JSPI</category>
<category>paint event</category>
<category>WebNN</category>
<description>A C program with a blocking main loop and a blocking modal dialog, drawing real elements with drawElementImage(). JSPI suspends it between paint events. Plus one edge filter as a WebNN graph and as C.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/wasm-ui/"><img src="https://html-in-canvas.page/wasm-ui/social.jpg" width="1200" height="630" alt="The page &quot;A WebAssembly loop that waits for the paint event&quot;"></a></p>
<p><strong>Question:</strong> Can a C program draw DOM elements from a main loop that blocks on the canvas paint event, and show a modal dialog of real buttons from a nested blocking loop?</p>
<p><strong>Short answer:</strong> Yes, with JavaScript Promise Integration: two JavaScript calls and no async code in C. The WebNN part couldn't be measured, navigator.ml is missing in the test browsers.</p>
<p>
A native UI program has a main loop that blocks until there's an event, and a modal dialog is a function that returns the answer.
A web page can't block. JavaScript Promise Integration (JSPI) lets a WebAssembly import return a promise while the WebAssembly code
sees an ordinary blocking call. I wanted to know two things: can a C program draw DOM elements with <code>drawElementImage()</code> from a loop that blocks
on the canvas <code>paint</code> event, and can it show a modal dialog made of real buttons from a nested blocking loop?
</p>
<h3>Findings</h3>
<ul>
<li><strong>Yes to both.</strong> <code>run()</code> in C is an endless loop that is called once. It draws real elements with <code>drawElementImage()</code>, blocks in <code>wait_event()</code>, and continues when the canvas fires <code>paint</code>. <code>ask()</code> blocks in the same import from a nested loop and returns 1 or 0 to its caller when a real <code>&lt;button&gt;</code> in the dialog is clicked. Measured in Chromium 157.</li>
<li><strong>The JavaScript for JSPI is two calls.</strong> <code>new WebAssembly.Suspending(fn)</code> on the import and <code>WebAssembly.promising(run)</code> on the export. The C source has no async code, no state machine and no Asyncify build step. The module is 3 KB.</li>
<li><strong>The loop does no work between events.</strong> With nothing happening the program draws 0 frames while the page has 30 animation frames. One change to a field gives one paint event and one frame. A focused text field gives a frame for each blink of its caret, because the browser repaints the field.</li>
<li><strong>Drawing after the promise settles still counts as drawing in the paint event.</strong> The program continues in a microtask of the <code>paint</code> listener. <code>drawElementImage()</code> worked there in every run, and <code>requestPaint()</code> called from there gives another paint event.</li>
<li><strong>The first frame has to wait for the first paint event.</strong> Before it the elements have no paint record and <code>drawElementImage()</code> throws. The page calls <code>run()</code> after the first <code>paint</code>.</li>
<li><strong>A blocking loop sees one pointer state per frame.</strong> A tap can begin and end between two paint events. The page queues each pointer change and gives the program one per frame, and asks for another paint while the queue isn't empty.</li>
<li><strong>A modal dialog needs the page to say what is under it.</strong> The browser hit tests an element wherever it was last drawn and doesn't know the program drew a dimmed layer and a dialog over it. The page sets <code>inert</code> on every element the program draws as not interactive, and on the dialog while it isn't drawn. In a 2D canvas that was enough: no <code>updateElementGeometry()</code> call was needed.</li>
<li><strong>The module can be called while <code>run()</code> is suspended.</strong> The edge filter is a second export of the same module and runs on the same memory while the main loop is stopped inside <code>wait_event()</code>.</li>
<li><strong>The pixels of a drawn element can be read back and filtered.</strong> <code>getImageData()</code> on the drawable canvas returns the pixels of the notes field, and the C filter takes about 10 ms for 900×220 pixels in the test browser. Chromium logs a notice that repeated readback is faster with <code>willReadFrequently</code>.</li>
<li><strong>WebNN wasn't measured.</strong> <code>navigator.ml</code> is missing from both test browsers (Chromium 153 and 157), and the plan lists it as an origin trial that needs a GPU. The graph code on this page was run only against a JavaScript stand-in for the seven WebNN calls it uses, where its output matched the C filter. Whether it builds and runs in a real WebNN implementation is unknown. The live check for it is expected to fail where <code>navigator.ml</code> is missing.</li>
<li><strong>The widgets the program draws have no DOM node.</strong> The slider and the Delete button can't be reached with the keyboard or a screen reader. The fields, the text and the dialog buttons can.</li>
<li><strong>Not verified on a phone.</strong> Tested in headless Chromium 157 at a 2.625 device scale with touch events: tapping, typing, dragging the slider and both dialog buttons. If the canvas loses its drawing context the page shows a message, and the program draws again when the context is restored.</li>
</ul>
<p>
This page follows <a href="https://html-in-canvas.page/native-ui/">DOM elements inside egui and Qt Quick apps</a>, where the toolkits keep their own frame loops.
Source: <a href="https://github.com/PaulKinlan/html-in-canvas-demos/tree/main/native/wasm-ui">native/wasm-ui</a>.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/wasm-ui.md">findings/wasm-ui.md</a> in the repository.</p>
<p>Measured in C157 (headless, 2.625 device scale, touch) on 2026-11-21. <code>native/wasm-ui/ui.c</code> is 170 lines of C built with <code>clang --target=wasm32 -nostdlib</code> (3 KB). Demo 28 of the Chrome APIs plan.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A C main loop that never returns, blocked on the canvas <code>paint</code> event through JSPI</td><td>works</td><td><code>new WebAssembly.Suspending(wait_event)</code> on the import, <code>WebAssembly.promising(run)</code> on the export. The promise is settled in the <code>paint</code> listener and the program draws with <code>drawElementImage()</code> in the microtask that follows.</td></tr>
<tr><td>The loop is idle between events</td><td>works</td><td>0 frames drawn during 30 animation frames. One changed field gives one paint event and one frame. A focused text field gives one frame per caret blink.</td></tr>
<tr><td>A blocking modal dialog made of a real element with two real buttons</td><td>works</td><td><code>ask()</code> has its own loop, suspends in the same import two C calls deep, and returns 1 or 0 to <code>run()</code>.</td></tr>
<tr><td>Elements under the dialog take no input</td><td>works with <code>inert</code></td><td>The browser hit tests an element where it was last drawn. The page sets <code>inert</code> on what the program draws as not interactive and on the dialog while it is not drawn. No <code>updateElementGeometry()</code> call was needed in a 2D canvas.</td></tr>
<tr><td>A tap reaches the program as a press and a release</td><td>needs a queue</td><td>Both pointer events can arrive between two paint events. The page queues pointer states and gives the program one per frame.</td></tr>
<tr><td><code>requestPaint()</code> called inside a <code>paint</code> listener</td><td>works</td><td>It gives a second paint event.</td></tr>
<tr><td>Calling another export while <code>run()</code> is suspended</td><td>works</td><td>The C edge filter runs on the same memory. About 10 ms for 900×220 pixels read with <code>getImageData()</code>.</td></tr>
<tr><td>The edge filter as a WebNN graph on the element's pixels</td><td>not verified</td><td><code>navigator.ml</code> is missing from C153 and C157.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first version of <code>ask()</code> waited before it drew, so the dialog appeared only after the next event. A nested loop has to draw first and then wait.</li>
<li>A press and a release dispatched in one task were seen by the program as a single state. The pointer queue fixed it.</li>
<li><code>setPointerCapture()</code> throws for a synthetic pointer event, which stopped the listener in the live checks. The call is wrapped.</li>
<li>A rule for <code>[data-ui]</code> also matched the buttons inside the dialog and stacked them at the canvas origin. The rule now matches only children of the canvas.</li></ul>
<h3>Not verified</h3>
<ul><li>WebNN. The graph code (cast, transpose, one 3×3 convolution with two filters, L2 norm, clamp, and the MLTensor calls) ran only against a JavaScript stand-in, where its output matched the C filter. The "Run the edge filter" button and the last live check on <code>/wasm-ui/</code> report the result in a browser with WebNN on.</li>
<li>A real phone (A159): touch on the slider and dialog, the keyboard over the canvas, and whether the 2D canvas keeps its context on load.</li>
<li>The slider and Delete button drawn by the program have no DOM node, so a screen reader cannot reach them. Not tested with one.</li></ul>
<p><a href="https://html-in-canvas.page/wasm-ui/">Open A WebAssembly loop that waits for the paint event</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Newer WebGPU features on element textures</title>
<link>https://html-in-canvas.page/webgpu-features/</link>
<guid isPermaLink="true">https://html-in-canvas.page/webgpu-features/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGPU</category>
<category>drawElementImageToTexture</category>
<category>dual-source-blending</category>
<category>immediates</category>
<description>A form and a block of text as WebGPU textures, drawn with texture swizzle, immediates, a float trail target, primitive_index and dual-source blending. Each has another way for devices without it, a compatibility mode tier and a WebGL route.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/webgpu-features/"><img src="https://html-in-canvas.page/webgpu-features/social.jpg" width="1200" height="630" alt="The page &quot;Newer WebGPU features on element textures&quot;"></a></p>
<p><strong>Question:</strong> Which newer WebGPU features are useful on a texture made from an element, and what is drawn on a device without them?</p>
<p>
A small form and a block of text are uploaded to WebGPU textures with <code>drawElementImageToTexture()</code> and drawn in five tiles.
Each tile uses one WebGPU feature that is newer than the first WebGPU release, when the device has it. When the device does not, the tile
draws the same picture another way. The table under the canvas says which is in use here.
</p>
<h3>How it works</h3>
<table>
<thead><tr><th>Feature</th><th>On this device</th><th>What it is used for</th></tr></thead>
<tbody>
<tr><td><b>Adapter</b><br><code>requestAdapter({ featureLevel })</code></td><td>…</td><td>A core adapter is asked for first. Where there is none, a compatibility mode adapter (OpenGL ES 3.1 class hardware) is asked for before the page gives up on WebGPU and uses WebGL.</td></tr>
<tr><td><b>Alpha as a mask</b><br><code>texture-component-swizzle</code></td><td>…</td><td>The glow shader reads a one-channel mask from <code>.r</code>. A second view of the form's texture, <code>createView({ swizzle: 'aaa1' })</code>, hands it the alpha channel there.</td></tr>
<tr><td><b>Values for each draw</b><br><code>var&lt;immediate&gt;</code>, <code>setImmediates()</code></td><td>…</td><td>Every draw has its own rectangle, tint and turn (48 bytes). They're set on the render pass before the draw, with no buffer and no bind group.</td></tr>
<tr><td><b>Trails</b><br><code>float32-blendable</code></td><td>…</td><td>The trail is a texture that is faded and added to every frame. In a float texture the sums go above 1.0 and the fade reaches zero.</td></tr>
<tr><td><b>Shards</b><br><code>primitive-index</code></td><td>…</td><td>The fragment shader tints and fades each of the 80 triangles by its number, read from <code>@builtin(primitive_index)</code>.</td></tr>
<tr><td><b>Subpixel text</b><br><code>dual-source-blending</code></td><td>…</td><td>The fragment shader writes the ink colour and a separate coverage for red, green and blue. The blend uses the second output as the factor for each channel.</td></tr>
</tbody>
</table>
<h3>Findings</h3>
<ul>
<li><strong>An element texture works with all five features.</strong> <code>drawElementImageToTexture()</code> fills an ordinary <code>rgba8unorm</code> texture, so a swizzled view of it, a float target fed from it and a dual-source blend over it need nothing special.</li>
<li><strong>A swizzled view needs its own <code>usage</code>.</strong> The element texture must have <code>RENDER_ATTACHMENT</code> for the upload. The swizzled view is made with <code>usage: TEXTURE_BINDING</code> so it isn't also a render target.</li>
<li><strong>Immediates replace a buffer and a bind group.</strong> <code>var&lt;immediate&gt; p: P;</code> in the shader, <code>immediateSize</code> on the pipeline layout and <code>pass.setImmediates(0, floats)</code> before each draw. The limit is <code>maxImmediateSize</code>, 64 bytes in Chromium 157. The other way here is one uniform buffer with a 256-byte slot for each draw and a dynamic offset.</li>
<li><strong>An 8-bit trail never fades out.</strong> Multiplying an 8-bit value by 0.95 and rounding stops near 10 out of 255, so old trails stay as a mark: after 200 fades the <code>rgba8unorm</code> trail is still 14 of 255 brighter than the background, and the float ones are at 0. Eight additions of the form read 251 of 255 from a float target and 201 from the 8-bit one, which stops at 1.0. <code>rgba16float</code> blends on every core device; <code>rgba32float</code> needs <code>float32-blendable</code> and can't be sampled with a filtering sampler, so the shader reads it with <code>textureLoad()</code>.</li>
<li><strong><code>primitive_index</code> is a fragment shader input only.</strong> Moving the shards apart happens in the vertex shader, which has to work the triangle out from <code>vertex_index / 3</code> anyway. For a list of separate triangles a flat varying carries the same number to the fragment shader, so the feature saves one varying here. It's needed when triangles share vertices through an index buffer.</li>
<li><strong>Subpixel text needs the canvas to match the screen's pixels.</strong> The canvas is sized from <code>devicePixelContentBoxSize</code>, and the text element is laid out at three times its shown size so each canvas pixel has 3 × 3 texels. The order red, green, blue is assumed. Most phone screens don't have that layout, so there the per-channel coverage shows as coloured edges and plain alpha is the better choice.</li>
<li><strong>A compatibility mode device runs every shader on this page.</strong> On the software adapter these pages are tested with, <code>requestAdapter({ featureLevel: 'compatibility' })</code> gives a device with lower limits (4096 pixel textures, 4 colour attachments) that still has swizzle, immediates and float blending, and its picture matches the core one. Flat varyings are written <code>@interpolate(flat, either)</code>, which compatibility mode requires.</li>
<li><strong>On a phone with a real GPU all ten checks pass.</strong> Reported from Chrome 159 on Android on 2026-11-21: the device has all four optional features, <code>primitive_index</code> matches the flat varying exactly, and the dual-source text has 7986 pixels whose red and blue differ by more than 24 while its channel average stays within 2 of 255 of plain alpha. The software adapter these pages are tested with has neither of those two features, so there the two checks report that they didn't run.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/webgpu-features.md">findings/webgpu-features.md</a> in the repository.</p>
<p>Measured in C157 (headless shell, software WebGPU adapter) on 2026-11-21, by drawing to an off-screen target and reading it back. The rows marked A159 are reported: Paul ran the page's live checks on his phone on 2026-11-21 and pasted the table (10 of 10 pass).</p>
<p>One page draws a form and a block of text, both uploaded with <code>drawElementImageToTexture()</code>, with one newer feature per tile. <code>webgpu({ features: true })</code> in <code>shared/backend.js</code> makes a second device that asks the adapter for each of <code>texture-component-swizzle</code>, <code>float32-blendable</code>, <code>dual-source-blending</code> and <code>primitive-index</code> that it lists. The device the other pages share is unchanged.</p>
<table><thead><tr><th>Feature</th><th>Use</th><th>Without it</th><th>Result</th></tr></thead><tbody><tr><td>Compatibility mode (<code>requestAdapter({ featureLevel: 'compatibility' })</code>)</td><td><code>webgpu({ compat: true })</code> gives a compatibility device where there is no core adapter; <code>pickBackend()</code> accepts <code>'webgpu-compat'</code> in its order</td><td>WebGL</td><td>The compatibility device (4096 pixel textures, 4 colour attachments) builds every shader on the page and its picture matches the core device within 2 of 255</td></tr>
<tr><td><code>texture-component-swizzle</code></td><td><code>createView({ swizzle: 'aaa1', usage: TEXTURE_BINDING })</code> hands an element's alpha to a shader that reads <code>.r</code></td><td>The shader is compiled again to read <code>.a</code></td><td>Same picture, largest difference 0 of 255</td></tr>
<tr><td>Immediates (<code>var&lt;immediate&gt;</code>, <code>setImmediates()</code>)</td><td>48 bytes for each draw with no buffer and no bind group; <code>maxImmediateSize</code> is 64</td><td>One uniform buffer, a 256-byte slot for each draw, dynamic offset</td><td>Same picture, largest difference 0 of 255</td></tr>
<tr><td><code>float32-blendable</code></td><td>An <code>rgba32float</code> trail target that is faded and added to each frame</td><td><code>rgba16float</code>, then <code>rgba8unorm</code></td><td>Float targets read 251 of 255 after 8 additions and 0 after 200 fades; <code>rgba8unorm</code> reads 201 and keeps a mark of 14</td></tr>
<tr><td><code>primitive-index</code></td><td><code>@builtin(primitive_index)</code> tints each triangle in the fragment shader</td><td><code>vertex_index / 3</code> as a flat varying</td><td>Reported, A159: same picture both ways, largest difference 0 of 255. Not in C157 (the software adapter does not have the feature)</td></tr>
<tr><td><code>dual-source-blending</code></td><td>Text with a separate coverage for red, green and blue (<code>@blend_src(1)</code>, <code>src1</code> blend factors)</td><td>The coverages averaged, plain alpha</td><td>Reported, A159: 7986 pixels have red and blue more than 24 apart, and the channel average is within 2.0 of 255 of the plain alpha picture. Not in C157</td></tr></tbody></table>
<ul><li>The WebGL 2 route draws the same frame as the WebGPU route with every feature off: mean difference 0.09 of 255 in the shards tile and 0.00 in the other four.</li>
<li><code>primitive_index</code> is a fragment input only. Moving triangles apart is vertex work, so it does not replace per-vertex data; for separate triangles a flat varying gives the fragment shader the same number.</li>
<li>Flat varyings must be <code>@interpolate(flat, either)</code> to compile on a compatibility device.</li>
<li>Subpixel text needs a canvas with one pixel for each screen pixel (<code>devicePixelContentBoxSize</code>) and assumes red, green, blue stripes. Most phone screens are not laid out that way.</li></ul>
<h3>Things that bit</h3>
<ul><li>A swizzled view of the element texture must be made with <code>usage: TEXTURE_BINDING</code>. The texture itself needs <code>RENDER_ATTACHMENT</code> for the upload, and a swizzled view cannot be a render target.</li>
<li><code>primitive_index</code> and <code>dual_source_blending</code> shaders do not parse unless the device has the feature, so each has a second shader source and the pipeline is built inside an error scope.</li>
<li>In an emulated phone the <code>ResizeObserver</code> device pixel size equals the CSS size. The page uses it only when it agrees with <code>devicePixelRatio</code>.</li>
<li>A canvas keeps the first kind of context it gave out. Changing route from WebGPU to WebGL replaces the canvas and moves its children across.</li></ul>
<h3>Reported from the phone (A159, 2026-11-21)</h3>
<ul><li>The page says "Drawn with WebGPU" and shows all five tiles. The last check reads the visible canvas: drawn with webgpu, 93% of sampled pixels have ink.</li>
<li>The device is a core device with all four optional features and immediates (up to 64 bytes).</li>
<li>Swizzle, immediates and <code>primitive_index</code> each match their other way with a largest difference of 0 of 255.</li>
<li>Float trails: the same numbers as C157 (251 and 0 for both float formats, 201 and 14 for <code>rgba8unorm</code>).</li>
<li><code>requestAdapter({ featureLevel: 'compatibility' })</code> gives an adapter that can also give core devices. A device made from it with no features asked for is a compatibility device (4096 pixel textures, 4 colour attachments), has every feature the core device has, and draws the same picture within 2 of 255.</li>
<li>WebGL against WebGPU with every feature off: mean difference 0.01 of 255 in the trails tile and 0.00 in the other four.</li></ul>
<h3>Not verified</h3>
<ul><li>What the "WebGPU compatibility mode" entry of the "Drawn with" menu shows on screen on the phone. The off-screen check of that device passes there.</li>
<li>Whether the per-channel text looks better or worse than plain alpha on the phone's screen. The check only shows that the channels differ.</li>
<li>A device without <code>dual-source-blending</code> or <code>primitive-index</code> other than the software adapter.</li></ul>
<p><a href="https://html-in-canvas.page/webgpu-features/">Open Newer WebGPU features on element textures</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>An app window drawn by a canvas</title>
<link>https://html-in-canvas.page/window-chrome/</link>
<guid isPermaLink="true">https://html-in-canvas.page/window-chrome/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Window Controls Overlay</category>
<category>app-region</category>
<category>manifest</category>
<category>elementFromPoint</category>
<description>An installable app whose title bar is an element of the canvas that covers the window. A simulated window on the page drags by the drawn title bar, and the installed app tests whether a real drag region follows the picture or the layout box.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/window-chrome/"><img src="https://html-in-canvas.page/window-chrome/social.jpg" width="1200" height="630" alt="The page &quot;An app window drawn by a canvas&quot;"></a></p>
<p><strong>Question:</strong> Can the title bar of an installed app be an element drawn by a canvas, and does a drag region follow the place where the element is drawn?</p>
<p><strong>Short answer:</strong> The bar, its tabs and its text field work in a simulated window, and the computed app-region is found at the drawn position. A real installed window hasn't been measured.</p>
<p>
An installed web app with <code>window-controls-overlay</code> may paint the title bar itself, and CSS marks the parts of it that drag the
window. I wanted to know whether one canvas can draw the whole window: a title bar that is a live element with tabs, a text field and window
buttons, the content under it, and a drag region that is drawn somewhere other than its layout box. The frame below runs the app in a
simulated window. Drag it by its title bar, press the tabs, and type in the title field. The same app can be installed to try the real window.
</p>
<h3>How it works</h3>
<p>
The app is one page with one canvas that covers the window. The title bar is a <code>&lt;header&gt;</code> with
<code>app-region: drag</code>, and its buttons and text field have <code>app-region: no-drag</code>. With the overlay on,
<code>navigator.windowControlsOverlay.getTitlebarAreaRect()</code> gives the rectangle the system buttons leave free. The app sizes the
header to that rectangle and draws it there. The canvas paints the full width of the strip first, so its colour continues under the system
buttons.
</p>
<p>
The simulated window is a frame with the same app in it. This page gives the app a simulated title bar rectangle and window position in
place of the real ones. To decide whether a press drags the window, it asks the frame's document for the element at the pointer and reads
the computed <code>app-region</code> of that element and its ancestors. That follows the position where the canvas drew the element. A real
window manager gets its drag regions from the browser by another route, so the simulation doesn't answer what a real window does. The two
tests inside the app do, once it's installed.
</p>
<h3>Findings</h3>
<ul>
<li><strong>One canvas can draw a whole window, title bar included.</strong> The bar is an element. Its tabs take clicks and its text field takes typing where the canvas draws them, in the simulated window, by mouse and by emulated touch.</li>
<li><strong>What the canvas adds to the bar is drawn around the element's picture.</strong> The gradient under the bar, the glow that follows the pointer and the grey of an inactive window are canvas drawing. The element itself has a transparent background.</li>
<li><strong>The computed <code>app-region</code> is readable on an element found at its drawn position.</strong> <code>elementFromPoint()</code> at the picture of the orange block returns the block, 150 px from its layout box, and its computed style says <code>drag</code>. At the layout box it returns the body. A simulated window built on those two calls therefore drags from the picture.</li>
<li><strong>Whether a real window drags from the picture or from the layout box isn't known.</strong> The browser sends the window manager a list of drag rectangles. This page can't see that list, and the test browser has no installed-app window. The app's two tests measure it from the change of <code>screenX</code> and <code>screenY</code>.</li>
<li><strong><code>window-drag</code> isn't in the test browsers.</strong> Chromium 153 and 157 accept <code>app-region: drag</code> and reject <code>window-drag: drag</code> in <code>CSS.supports()</code>. The app sets both.</li>
<li><strong>The windowing calls are missing in a tab.</strong> <code>window.minimize</code>, <code>maximize</code>, <code>restore</code>, <code>setResizable</code> and <code>setShape</code> are undefined in the test browsers, and so is <code>navigator.install</code>. The app's buttons report what they find where it runs. Window Shape is limited to allowlisted Isolated Web Apps on ChromeOS and wasn't tried.</li>
<li><strong>A drag region gives the page no pointer events.</strong> In a real window, a pointer over the bar's drag region is the system's, so the glow can't follow it there. It follows the pointer over the tabs and the field, which aren't drag regions.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/fold.md">findings/fold.md</a> in the repository.</p>
<h3><code>/window-chrome/</code>, <code>app.html</code>, <code>app.webmanifest</code></h3>
<p>An installable app whose window is one canvas. The title bar is a <code>&lt;header&gt;</code> child of the canvas with <code>app-region: drag</code>. The page runs the app in a frame with a simulated window around it. Tested in headless Chromium 157 with a mouse and emulated touch, 2026-11-21. No installed app window was used.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>A title bar element drawn by the canvas, with tabs and a text field in it</td><td>works in the simulated window</td><td>The bar is sized to the title bar rectangle and drawn there. A tab takes a click and the field takes typing at the drawn position, by mouse and by emulated touch.</td></tr>
<tr><td>Canvas drawing around the bar</td><td>works</td><td>The gradient behind the bar, a glow under the pointer and the grey of an inactive window are drawn by the canvas around the picture of the element.</td></tr>
<tr><td>Read <code>app-region</code> at a drawn position</td><td>works</td><td><code>elementFromPoint()</code> at the picture of an element drawn 150 px from its layout box returns the element, and its computed <code>app-region</code> is <code>drag</code>. At the layout box it returns what is drawn there. A simulated window built on those two calls drags from the picture.</td></tr>
<tr><td><code>window-drag</code></td><td>not in Chromium 153 or 157</td><td><code>CSS.supports('window-drag: drag')</code> is false. <code>app-region: drag</code> is supported.</td></tr>
<tr><td><code>window.minimize()</code>, <code>maximize()</code>, <code>restore()</code>, <code>setResizable()</code>, <code>setShape()</code>, <code>navigator.install()</code></td><td>undefined in a tab</td><td>The app's buttons report what exists where it runs.</td></tr></tbody></table>
<p>Not verified: everything about a real window. Whether the window controls overlay hands the canvas the strip beside the system buttons as expected, whether a real drag region is at the picture of the element or at its layout box (the app's "Test 1" and "Test 2" measure it from <code>screenX</code> and <code>screenY</code> once installed), whether <code>updateElementGeometry()</code> changes that, and the windowing calls in an installed window. Window Shape needs an allowlisted Isolated Web App on ChromeOS and was not tried.</p>
<p><a href="https://html-in-canvas.page/window-chrome/">Open An app window drawn by a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A worker as the video compositor</title>
<link>https://html-in-canvas.page/worker-compositor/</link>
<guid isPermaLink="true">https://html-in-canvas.page/worker-compositor/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>worker</category>
<category>MediaStreamTrackProcessor</category>
<category>ElementImage</category>
<category>VideoFrame</category>
<description>A worker reads video frames from a MediaStreamTrackProcessor, draws transferred ElementImage snapshots of live HTML over them and writes a video track. The picture and the track keep running while the main thread is blocked.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/worker-compositor/"><img src="https://html-in-canvas.page/worker-compositor/social.jpg" width="1200" height="630" alt="The page &quot;A worker as the video compositor&quot;"></a></p>
<p><strong>Question:</strong> Can a worker compose camera or video frames with snapshots of live DOM and produce a video track, with no <code>captureStream()</code> and no work on the main thread per frame?</p>
<p><strong>Short answer:</strong> Yes, through transferred streams. Chromium 157 has neither <code>MediaStreamTrackProcessor</code> nor <code>VideoTrackGenerator</code> in a worker, so the page makes both ends and transfers their streams.</p>
<p>
A worker reads video frames, draws a snapshot of the HTML below over each one, and writes the result to a video track.
The first picture is the worker's canvas. Type in the caption field and press the buttons in it. Then block the main thread: the picture and the track keep running.
</p>
<h3>How it works</h3>
<ul>
<li>An <code>ElementImage</code> can be drawn only into the canvas it was captured from. So the worker doesn't make its own canvas. The page calls <code>transferControlToOffscreen()</code> on the drawable canvas and the worker draws into that. The canvas on the page shows what the worker draws.</li>
<li>The page listens for <code>paint</code>. Each time, it calls <code>canvas.captureElementImage(scene)</code> and transfers the snapshot to the worker. The worker keeps the newest one and closes the one before.</li>
<li>Video frames reach the worker as <code>VideoFrame</code> objects. The first source reads the WebM clip in the worker and decodes it there with <code>VideoDecoder</code>. The camera and the second clip source use a <code>MediaStreamTrackProcessor</code> on a track from <code>getUserMedia()</code> or <code>video.captureStream()</code>.</li>
<li>A 2D context draws RGB and the frames are YUV. "Frame to RGB" picks how the worker converts them: <code>copyTo()</code> of the planes and a loop in script, <code>createImageBitmap()</code>, or <code>drawImage()</code> of the frame itself. Auto uses <code>copyTo()</code> for I420 and NV12 frames and <code>createImageBitmap()</code> for the rest.</li>
<li>For each frame the worker draws the frame, draws the snapshot, wraps the canvas in a <code>VideoFrame</code> with the input frame's timestamp and writes it to the track.</li>
<li>The worker's <code>drawElementImage()</code> also sets where the element is for hit testing on the main thread. The field and the buttons in the picture take input where they are drawn.</li>
<li>While the main thread is blocked no <code>paint</code> runs, so the worker draws the last snapshot it has. The video frames keep changing.</li>
</ul>
<h3>Findings</h3>
<p>From Chromium 157, headless, with software rendering and software video decoding. The rows above say what your browser does.</p>
<ul>
<li><strong>Works: a worker composes video frames and DOM into a track.</strong> The frames come from a transferred <code>ReadableStream</code>, the DOM from transferred <code>ElementImage</code> snapshots, and the output goes to a transferred <code>WritableStream</code>. No call to <code>captureStream()</code> on the canvas is needed.</li>
<li><strong>Not in Chromium 157: the two calls the specification gives a worker.</strong> <code>MediaStreamTrackProcessor</code> and <code>VideoTrackGenerator</code> aren't defined in a worker, and a <code>MediaStreamTrack</code> can't be transferred (<code>DataCloneError</code>). The window has <code>MediaStreamTrackProcessor</code> and the older <code>MediaStreamTrackGenerator</code>, and their streams can be transferred. The page tries the standard route first and reports which one it used.</li>
<li><strong>Limit: the snapshot must be drawn into its source canvas.</strong> Drawing it into an <code>OffscreenCanvas</code> made in the worker throws. The output frame is therefore the size of the canvas on the page, and that canvas shows the composition whether or not it is wanted there.</li>
<li><strong>Works: the main thread can stop.</strong> With the clip decoded in the worker, the worker read and wrote 23 frames during a 0.8 s block and the track delivered 22. The HTML in them is the last snapshot. Input to the overlays waits until the block ends.</li>
<li><strong>Fails during a block: <code>drawImage(VideoFrame)</code>, <code>createImageBitmap(VideoFrame)</code> and <code>texImage2D(VideoFrame)</code> of an I420 frame in a worker.</strong> Each one waited until the main thread was free, so the worker composed one frame or none. <code>copyTo()</code> in the frame's own format didn't wait. The worker therefore reads the planes and converts them to RGB in a loop, which took about 4 ms for 640 by 360 here. Frames the worker made from a canvas (BGRA) convert with <code>createImageBitmap()</code> during a block. This was measured with software rendering. A device with a GPU may not have the wait.</li>
<li><strong>Fails during a block: <code>video.captureStream()</code> as the source.</strong> It delivered no frame while the main thread was blocked. A camera track delivered 20 frames a second through the same block (Chromium's fake camera).</li>
<li><strong>Fails during a block: <code>captureStream()</code> of the canvas on the page as the way out.</strong> It still works after <code>transferControlToOffscreen()</code>, and delivered 10 frames in a second, but none while the main thread was blocked. The track written by the worker didn't stop.</li>
<li><strong>Works: WebGL 2 in the worker.</strong> <code>texElementSubImage2D()</code> takes the transferred snapshot and <code>texImage2D()</code> takes a <code>VideoFrame</code> on the transferred canvas, so the looks could be shaders. The page uses the 2D context, which is the lighter route.</li>
<li><strong>Works: hit testing.</strong> The canvas buffer is 640 px wide and the canvas is shown narrower. The worker passes the buffer size to <code>drawElementImage()</code>, and the buttons are hit where they are drawn.</li>
<li><strong>Not verified here:</strong> a real camera, hardware-decoded frames (which can arrive as NV12 or with no format, not I420), which conversions wait for the main thread on a device with a GPU, the frame rate on a phone, and whether Chrome 159 has the worker calls. The live checks answer these on your device.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/worker-compositor.md">findings/worker-compositor.md</a> in the repository.</p>
<p>Chromium 157 headless, software rendering and software video decoding, 2026-11-21. Measured by the page's live checks and by scripts that drove the page with Playwright. The camera in these runs is Chromium's fake camera (<code>--use-fake-device-for-media-stream</code>).</p>
<p>The page transfers a drawable canvas to a worker. The worker reads <code>VideoFrame</code>s, draws a transferred <code>ElementImage</code> of the overlay HTML over each one, and writes <code>new VideoFrame(canvas)</code> to a video track. The worker is <code>public/worker-compositor/compositor.js</code>.</p>
<h3>Getting frames into the worker and a track out</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>MediaStreamTrackProcessor</code> in a worker</td><td>not defined</td><td>The specification defines it for workers only. Chromium 157 has it in the window only.</td></tr>
<tr><td><code>VideoTrackGenerator</code> in a worker</td><td>not defined</td><td>The window has the older <code>MediaStreamTrackGenerator</code> and no <code>VideoTrackGenerator</code>.</td></tr>
<tr><td><code>postMessage(track, [track])</code> to a worker</td><td>fails</td><td><code>DataCloneError</code>: a <code>MediaStreamTrack</code> is not transferable.</td></tr>
<tr><td><code>MediaStreamTrackProcessor</code> in the window, <code>readable</code> transferred to the worker</td><td>works</td><td>Frames arrive in the worker as I420, 640×360 from the clip and from the fake camera.</td></tr>
<tr><td><code>MediaStreamTrackGenerator</code> in the window, <code>writable</code> transferred to the worker</td><td>works</td><td>The worker writes <code>new VideoFrame(canvas, { timestamp })</code>. A <code>&lt;video&gt;</code>, <code>MediaRecorder</code> and <code>RTCPeerConnection</code> on the page take the track.</td></tr>
<tr><td>Timestamps</td><td>kept</td><td>18 of 18 frames read back from the output track carried the timestamp of an input frame.</td></tr>
<tr><td>Single <code>VideoFrame</code>s made on the page (<code>new VideoFrame(video)</code>) and posted</td><td>works</td><td>The route for a browser with no <code>MediaStreamTrackProcessor</code>. Each frame costs a main-thread task.</td></tr>
<tr><td>The WebM clip fetched, read and decoded with <code>VideoDecoder</code> in the worker</td><td>works</td><td>A 40 line WebM reader finds 300 VP9 frames. Frames arrive as I420. Nothing passes through the main thread.</td></tr>
<tr><td><code>captureStream()</code> on the page's canvas after <code>transferControlToOffscreen()</code></td><td>works</td><td>10 frames in 1 s while the worker drew 30. A second way out, with no generator.</td></tr></tbody></table>
<h3>Drawing the DOM in the worker</h3>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>drawElementImage(ElementImage)</code> over a video frame on the transferred canvas</td><td>works</td><td>Video pixel <code>rgb(16 64 192)</code> and HTML pixel <code>rgb(255 0 255)</code> read back in the worker. 0.2 ms for a 320×180 frame.</td></tr>
<tr><td>The snapshot drawn into an <code>OffscreenCanvas</code> made in the worker</td><td>fails</td><td><code>InvalidStateError</code>: "The source was captured from a different canvas." The output canvas has to be the page's canvas, at its buffer size.</td></tr>
<tr><td>A CSS animation in the scene</td><td>one snapshot per paint</td><td>61 <code>paint</code> events and 61 snapshots in 1 s. <code>captureElementImage()</code> plus <code>postMessage()</code> took 0.05 ms.</td></tr>
<tr><td>A button in a 320 px buffer shown 160 px wide, drawn by the worker with the buffer size</td><td>hit where drawn</td><td>Its box is 35×25 px and <code>elementFromPoint()</code> finds it. A touch on the drawn buttons and typing in the drawn field worked at 412 px.</td></tr>
<tr><td>WebGL 2 on the transferred canvas: <code>texElementSubImage2D(ElementImage)</code> and <code>texImage2D(VideoFrame)</code> in one shader</td><td>works</td><td>Both textures read back through the shader. The page's looks use the 2D context.</td></tr></tbody></table>
<h3>With the main thread blocked</h3>
<p>Each row blocks the main thread with a busy loop for 0.8 s (2 s for the button on the page) and counts frames in the worker.</p>
<table><thead><tr><th>Source and conversion</th><th>Frames composed during the block</th><th>Notes</th></tr></thead><tbody><tr><td>Clip decoded in the worker, <code>copyTo()</code> of the planes and a YUV to RGB loop in script</td><td>23 in 0.8 s, 58 in 2 s</td><td>The track delivered 22 to a second processor. About 4 to 6 ms per 640×360 frame.</td></tr>
<tr><td>Fake camera through a transferred <code>readable</code>, same conversion</td><td>40 in 2 s</td><td>The camera's rate was 20 a second.</td></tr>
<tr><td>Pattern drawn in the worker (BGRA frames from an <code>OffscreenCanvas</code>), <code>createImageBitmap()</code></td><td>58 in 2 s</td><td></td></tr>
<tr><td>Clip decoded in the worker, <code>drawImage(VideoFrame)</code></td><td>1 read, 0 written</td><td>The call waits for the main thread.</td></tr>
<tr><td>Clip decoded in the worker, <code>createImageBitmap(VideoFrame)</code></td><td>1 read, 0 written</td><td>The promise settles after the block.</td></tr>
<tr><td>I420 camera frame, <code>texImage2D(VideoFrame)</code> in a worker WebGL 2 context</td><td>1 read, 0 done</td><td>Measured in a script, not a live check.</td></tr>
<tr><td><code>copyTo(buffer, { format: 'RGBA' })</code> of a canvas-made frame</td><td>1</td><td>Measured in a script. <code>copyTo()</code> with no format conversion did not wait.</td></tr>
<tr><td>Clip played by a <code>&lt;video&gt;</code>, <code>video.captureStream()</code></td><td>0 read</td><td>The element's capture stops delivering frames.</td></tr>
<tr><td>Output through <code>captureStream()</code> of the page's canvas</td><td>0 delivered</td><td>The worker drew 18 frames in that time.</td></tr>
<tr><td><code>paint</code> events and new snapshots</td><td>0</td><td>The worker draws the last snapshot it has.</td></tr></tbody></table>
<h3>Things that bit</h3>
<ul><li>The first version drew each frame with <code>drawImage(frame)</code>. It ran at the full rate and stopped completely when the main thread was blocked, including for frames the worker made itself. The cause was the YUV to RGB step, not the read loop: a worker that only read and closed frames kept its rate.</li>
<li><code>MediaStreamTrackProcessor</code> frames from the clip have <code>codedWidth</code> 704 and a visible width of 640. <code>copyTo()</code> with no rectangle copies the visible rectangle, so the conversion sizes its buffers from <code>visibleRect</code>.</li>
<li>A message handler that awaits <code>createImageBitmap()</code> must keep the read loop in order. The loop awaits each compose before the next <code>read()</code>.</li>
<li>The fixture box of the check harness takes taps. As on the other media pages it is set to <code>pointer-events: none</code> except during an <code>elementFromPoint()</code> call.</li></ul>
<h3>Not verified</h3>
<ul><li>Whether the conversions that waited for the main thread also wait on a device with a GPU. The four "blocked main thread" live checks answer this on the phone, and the "Frame to RGB" menu with the block button shows it on the visible demo.</li>
<li>Hardware-decoded frames. They can arrive as NV12 or with <code>format</code> null. The script conversion handles I420, I420A and NV12 and falls back to <code>createImageBitmap()</code> for the rest. NV12 was not run.</li>
<li>A real camera, and the frame rate and compose time on a phone. The status lines under the demo report both.</li>
<li>Whether Chrome 159 for Android has <code>MediaStreamTrackProcessor</code> or <code>VideoTrackGenerator</code> in a worker. The two "standard route" live checks report it, and the page uses those routes first when they exist. That code path has not run.</li>
<li>Sound. The output track is video only.</li></ul>
<h3>Open ideas</h3>
<ul><li>The looks as WebGL 2 shaders in the worker, with the snapshot and the frame as textures.</li>
<li>Sound: an <code>AudioWorklet</code> beside the worker and an audio track added to the output stream.</li>
<li>An encoder in the same worker (<code>VideoEncoder</code>) that writes a file with <code>lib/webm-mux.js</code>, so a recording also survives a blocked main thread.</li></ul>
<p><a href="https://html-in-canvas.page/worker-compositor/">Open A worker as the video compositor</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>HTML panels in a real room</title>
<link>https://html-in-canvas.page/xr-room/</link>
<guid isPermaLink="true">https://html-in-canvas.page/xr-room/</guid>
<pubDate>Sat, 21 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebXR</category>
<category>hand tracking</category>
<category>plane detection</category>
<description>WebXR panels pressed with a tracked fingertip, attached to detected walls and tables with anchors, hidden behind real objects by depth sensing, and shown as an XR quad layer. A simulated room runs the same code without a headset.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/xr-room/"><img src="https://html-in-canvas.page/xr-room/social.jpg" width="1200" height="630" alt="The page &quot;HTML panels in a real room&quot;"></a></p>
<p><strong>Question:</strong> Can HTML panels use what a WebXR session knows about the room: fingertips, detected walls and tables, anchors, depth and compositor layers?</p>
<p><strong>Short answer:</strong> In a simulated room and a headset emulator, fingertip presses, plane snapping and anchors work. Detected planes, depth and quad layers are unverified until the page runs on a device.</p>
<p>
Two HTML panels for a WebXR session that knows about the room. A tracked fingertip presses buttons the way it would on a touch screen.
The panels attach to walls and tables from plane detection and stay there with anchors. Depth sensing hides them behind real objects.
One panel can be given to the headset's compositor as an <code>XRQuadLayer</code>.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Measured in the simulated room.</strong> A fingertip position is enough to drive DOM controls: distance to the panel gives hover, press and release, and the ray pointer from <code>html3d.js</code> supplies the events. Buttons, a slider and a scrolling list work. Snapping to a plane is a pose change, and hit testing doesn't notice because rays are mapped through UV coordinates.</li>
<li><strong>Not measured: everything that needs a device.</strong> Hand joints, detected planes, anchors, the depth texture and quad layers don't exist in the browser this was written in. Each has a row in the table above that a real session fills in.</li>
<li><strong>Open: can <code>texElementSubImage2D()</code> write into a layer's texture?</strong> The layer code tries it and falls back to copying the texture it already has. The "layer" row says which path ran.</li>
<li><strong>Open: does <code>paint</code> fire during an AR session on a phone?</strong> The "paints" row counts them. If they stop, textures are uploaded from the last paint record instead.</li>
<li><strong>Depth occlusion hides pixels, not input.</strong> three.js draws the sensed depth into the depth buffer, so a panel behind a chair is not drawn there. A ray or fingertip still reaches the panel, because the page has no depth values to test against unless it asks for CPU depth.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/3d.md">findings/3d.md</a> in the repository.</p>
<h3>Panels in a real room (<code>/xr-room/</code>, <code>lib/xr-room.js</code>)</h3>
<p>Demo 24 of the Chrome APIs plan. Measured on 2026-11-21 in headless Chromium 157 in two ways: a simulated room on the page (a pointer-driven fingertip, a wall and a table standing in for detected planes, a column standing in for a real object) and the IWER headset emulator (<code>?emulate=1</code>). Neither is a device.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Detail</th></tr></thead><tbody><tr><td>A fingertip position as a pointer</td><td>works, simulated and emulated</td><td><code>FingerPointer</code> takes one world position per frame. Within 20 cm in front of a panel it moves the pointer, at 8 mm it presses, past 2.5 cm it releases and clicks. Buttons, a range input and a scrolling list respond. In the emulator the position comes from three's <code>getHand(i).joints['index-finger-tip']</code>, the same path a tracked hand uses.</td></tr>
<tr><td>A press that starts on plain content scrolls</td><td>works</td><td>After 8 px of travel the nearest scroller is scrolled and the release is not a click.</td></tr>
<tr><td>Snap a panel to a plane</td><td>works with simulated planes</td><td><code>snapToPlane()</code> takes the <code>XRPlane</code> shape (pose matrix, polygon in x and z, orientation). Input needs no change after the move because it is mapped through the mesh's UVs. No real <code>detectedPlanes</code> set has been read.</td></tr>
<tr><td>Anchor a placed panel</td><td>works in the emulator</td><td><code>frame.createAnchor()</code> succeeds in IWER and the pose is re-read every frame. A real anchor moving as the map is refined has not been seen.</td></tr>
<tr><td>Depth occlusion</td><td>simulated only</td><td>three.js draws a GPU depth texture into the depth buffer when the session provides one. The emulator grants <code>depth-sensing</code> as <code>gpu-optimized</code> but supplies no texture. On the page, the column writes depth or does not. A session that only offers <code>cpu-optimized</code> depth gets no occlusion from this page.</td></tr>
<tr><td>Occlusion and input</td><td>by design</td><td>Depth hides pixels only. A ray or fingertip still reaches a panel behind a real object, because the page has no depth values to test against.</td></tr>
<tr><td>The status panel as an <code>XRQuadLayer</code>, filled with <code>texElementSubImage2D()</code></td><td>not verified</td><td><code>ElementQuadLayer</code> tries a direct upload into the layer's texture and falls back to a framebuffer blit from the panel's own texture. The emulator does not grant <code>layers</code>. The "layer" row on the page says which path ran.</td></tr></tbody></table>
<p>To settle on a device: whether hand joints, planes and depth are granted on Android Chrome and on a headset, whether <code>paint</code> keeps firing in AR, and whether <code>texElementSubImage2D()</code> accepts a layer's colour texture. The page's "What a session reports" table records each after a session ends.</p>
<p><a href="https://html-in-canvas.page/xr-room/">Open HTML panels in a real room</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Accessibility audit</title>
<link>https://html-in-canvas.page/a11y/</link>
<guid isPermaLink="true">https://html-in-canvas.page/a11y/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>accessibility tree</category>
<category>focus</category>
<category>forced-colors</category>
<description>Probes of focus, selection, find, zoom and forced colours for DOM drawn in a canvas, a table of how each pattern on this site holds up, the same audit run over every demo, and a short list to try with a screen reader.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/a11y/"><img src="https://html-in-canvas.page/a11y/social.jpg" width="1200" height="630" alt="The page &quot;Accessibility audit&quot;"></a></p>
<p><strong>Question:</strong> Which accessibility features work for DOM drawn in a canvas, and which techniques on this site break them?</p>
<p>
The claim for HTML-in-canvas is that the pixels are still elements, so they can be focused, searched and selected and they're in the accessibility tree. I wanted to check that, so this page tests it four ways: probes of the API, a table of the patterns used on this site, the same audit run over every page here, and a short list that only a person can do.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The claim holds for elements that are drawn.</strong> Elements drawn with <code>drawElementImage</code> keep their role, name, focus, caret, selection, find-in-page match and forced-colours rendering, at the place they are drawn, including when rotated or drawn by a worker.</li>
<li><strong>An element you don't draw is still there.</strong> Every drawable child stays in the tab order and the accessibility tree whether or not the paint handler draws it. Demos that keep spare elements in the canvas create invisible tab stops. The fix is one attribute (<code>inert</code>), and you have to add it yourself.</li>
<li><strong>WebGL breaks the link between pixels and elements</strong> until the author calls <code>updateElementGeometry</code>: the texture is on screen but focus rings, hit testing and screen magnifier tracking still point at the element's layout position.</li>
<li><strong>Pixels sent out of the canvas have no accessibility information.</strong> Mirrors, other tabs and other origins receive bitmaps. Those canvases need their own label or a link back to the live element.</li>
<li><strong>The patterns only differ under zoom.</strong> Slots, a shadow root on body, a worker, a WebGL texture: the accessibility tree, Tab order, find and selection come out the same in all of them. Patterns that position the element with their own transform fall out of step with the CSS <code>zoom</code> property.</li>
<li><strong>Always pass a size to <code>drawElementImage</code>.</strong> Without one it draws in device pixels, so after <code>ctx.scale(devicePixelRatio)</code> the element is too big on every HiDPI screen. A canvas sized from <code>devicePixelContentBoxSize</code> hides this under DevTools device emulation, where that box stays in CSS pixels.</li>
<li><strong>The page has to handle zoom.</strong> Nothing draws a canvas again when the page is zoomed. <code>&lt;canvas-slot&gt;</code> does it with a device-pixel ResizeObserver. Most of the canvases I wrote by hand don't.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/a11y.md">findings/a11y.md</a> in the repository.</p>
<p>Measured in Chromium 157 headless on 2026-11-20: in-page probes, plus the DevTools protocol for the accessibility tree, real key and mouse input, IME composition and forced-colours emulation. Screen reader output, the find bar, IME candidate windows, native popups and OS magnifiers are not automated: <code>/a11y/</code> section C is the list to try by hand.</p>
<table><thead><tr><th>Check</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>Accessibility tree</td><td>works</td><td>Canvas children are ordinary nodes under a "Canvas" node, with the same roles and names as outside a canvas.</td></tr>
<tr><td>Tab order, focus ring, caret</td><td>works</td><td>Real Tab walks canvas children in DOM order. Focus rings, carets and typed text are painted, and each focus change fires <code>paint</code> with the right <code>changedElements</code>.</td></tr>
<tr><td>Geometry (<code>getBoundingClientRect</code>, <code>elementFromPoint</code>, <code>scrollIntoView</code>)</td><td>works</td><td>Follows where the element is drawn, including under rotation and scale.</td></tr>
<tr><td>Mouse: click, caret placement, drag and double-click selection</td><td>works</td><td></td></tr>
<tr><td>Selection highlight, <code>window.find()</code></td><td>works</td><td>Both are painted into the canvas.</td></tr>
<tr><td>IME composition (<code>Input.imeSetComposition</code>)</td><td>works</td><td>Composition events fire and composing text is painted.</td></tr>
<tr><td>Forced colours, system colours, <code>light-dark()</code></td><td>works</td><td>Painted with their real values. The explainer allows system colours to be left out; this build paints them.</td></tr>
<tr><td>A drawable child the paint handler never draws</td><td>hazard</td><td>Still a Tab stop and still in the accessibility tree, reported at the canvas origin. Focus lands on nothing visible. <code>inert</code> on undrawn children fixes it; nothing does that for you.</td></tr>
<tr><td>WebGL (<code>texElementSubImage2D</code>)</td><td>hazard</td><td>No geometry until the author calls <code>updateElementGeometry</code>: the texture is on screen but hit testing and focus position are not.</td></tr>
<tr><td>Pixel mirrors (<code>drawImage(canvas)</code>, other tabs, other origins)</td><td>hazard</td><td>A plain canvas with no role, name, focus or text. Needs its own label.</td></tr>
<tr><td>Zoom</td><td>author's job</td><td>Layout and hit testing follow, but a canvas with a fixed <code>width</code> attribute is stretched. <code>&lt;canvas-slot&gt;</code> resizes itself with a device-pixel ResizeObserver; most hand-written canvases here do not.</td></tr></tbody></table>
<p>Per-demo results (the same audit, <code>public/lib/a11y-audit.js</code>, run over every page in <code>shared/demos.js</code>): geometry, focus, names, find and selection hold up wherever content is actually drawn. The recurring caveats are canvases that go soft at 150% zoom (<code>/slot-bare/</code>, <code>/offscreen/</code>, <code>/cross-origin/</code>, <code>/transitions/</code>, <code>/time-scrubber/</code>, <code>/particles/</code>), continuous animation with no <code>prefers-reduced-motion</code> handling (<code>/slot/</code>, <code>/transitions/</code>, <code>/particles/</code>), unlabelled pixel-only canvases (<code>/cross-origin/</code>, <code>/transports/</code>), and one invisible tab stop: the lent card's button on <code>/cross-origin/</code> was not hit-testable in the audit frame.</p>
<h3>Pattern by pattern (<code>/a11y/</code> section B, <code>/a11y/pattern.html?p=…</code>)</h3>
<p>The same card (heading, sentence, text field, button, link) built into a canvas thirteen ways, measured live, plus a recording made from outside with the DevTools protocol (<code>a11y/patterns-recorded.json</code>: real accessibility tree, real Tab key, real mouse, real devicePixelRatio 1.5).</p>
<table><thead><tr><th>Pattern</th><th>Accessibility tree</th><th>Focus order</th><th>Find in page</th><th>Selection</th><th>Zoom</th></tr></thead><tbody><tr><td>Child of the canvas, <code>&lt;canvas-slot&gt;</code>, bare slot in a shadow canvas, <code>light-slots.js</code></td><td>✓</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>Shadow root on <code>&lt;body&gt;</code>, page overlay canvas</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td>Drawn by a worker (<code>&lt;canvas-slot worker&gt;</code>)</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td><td>✓</td></tr>
<tr><td><code>&lt;dom-portal&gt;</code>, Shader CSS, <code>&lt;dom-lens&gt;</code>, <code>&lt;physical-ui&gt;</code></td><td>✓</td><td>✓</td><td>✓</td><td>✓</td><td>! CSS <code>zoom</code></td></tr>
<tr><td><code>&lt;live-transition&gt;</code></td><td>✓</td><td>✓</td><td>✓</td><td>✓</td><td>! stretched under CSS <code>zoom</code></td></tr>
<tr><td>Pixel mirror (other tab, other origin, video)</td><td>✗</td><td>✗</td><td>✗</td><td>✗</td><td>!</td></tr></tbody></table>
<ul><li><strong>How the DOM gets into the canvas does not matter to assistive technology.</strong> In every live pattern the accessibility tree has the same four nodes with the same roles and names, as children of one <code>Canvas</code> node; a real Tab key visits field, button, link in DOM order; <code>window.find()</code> finds and highlights the text; a real mouse drag selects it. Slots, shadow roots on body, workers, WebGL textures: all the same.</li>
<li><strong>The differences are all in zoom.</strong> Patterns that place the element with their own transform (<code>updateElementGeometry</code>, or a canvas sized from <code>devicePixelRatio</code>) ignore the CSS <code>zoom</code> property: the page grows, the drawing grows, but the element's reported box stays the old size, so clicks near the far edges miss. Real browser zoom is a devicePixelRatio change, and at a real ratio of 1.5 all twelve live patterns are sharp and clickable.</li>
<li><code>&lt;physical-ui&gt;</code> is the one pattern where a mouse drag does not select text: the drag grabs the material. Keyboard selection and find still work.</li>
<li>A pixel mirror fails everything, by construction. It needs a label and a way back to the live element.</li>
<li><strong><code>drawElementImage(el, x, y)</code> without a size draws in device pixels.</strong> On a real HiDPI screen the element comes out at <code>devicePixelRatio</code> × its CSS size in canvas pixels, which is right for an unscaled context and wrong after <code>ctx.scale(devicePixelRatio, devicePixelRatio)</code>: it is then drawn (and hit-tested) dpr times too large. Pass the size: <code>drawElementImage(el, x, y, el.offsetWidth, el.offsetHeight)</code>. Measured at 1, 1.5 and 2 with <code>--force-device-scale-factor</code>.</li>
<li><strong>Emulated device pixel ratios mislead in a different way.</strong> DevTools device emulation and Playwright's <code>deviceScaleFactor</code> change <code>devicePixelRatio</code> and the snapshot size, but <code>devicePixelContentBoxSize</code> keeps reporting CSS pixels. A canvas sized from that box stays at 1× under emulation, its scale factor is 1, and the oversize drawing never shows. Test HiDPI with <code>--force-device-scale-factor</code> (and no viewport emulation), or on a device. The default size is also fractional at real phone ratios (262.33 × 104.8 for a 100 × 40 element at 2.625, measured in the motion thread), one more reason to pass the size.</li></ul>
<h3>Staying calm on a phone</h3>
<ul><li>Live checks that run on load are the main way a demo misbehaves on a phone: a test that calls <code>focus()</code> on a field opens the keyboard, <code>scrollIntoView</code> or moving a focused element makes the browser scroll the page, and rows of results arriving push the demo around.</li>
<li>The audit now measures this for every demo, before it touches the page: scroll position still at the top, nothing focused, cumulative layout shift while loading, and whether each canvas shows a picture (<code>canvasState(canvas)</code>: drawn, blank, one solid colour, WebGL context lost). <code>/a11y/?url=/slot/</code> checks one page.</li>
<li>A WebGL canvas reads back empty outside a frame, so it is sampled from inside <code>requestAnimationFrame</code> callbacks, and an empty read is reported as "could not be read", not "blank".</li>
<li>What keeps a test page calm: fixtures in a <code>position: fixed</code> strip inside the viewport (nothing to scroll to), <code>inputmode="none"</code> on any field a test focuses (focus without the keyboard), restore scroll after a run, and start anything heavy from a button on touch devices (<code>(hover: hover) and (pointer: fine)</code> tells them apart).</li></ul>
<p><a href="https://html-in-canvas.page/a11y/">Open Accessibility audit</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Infinite board of live pages</title>
<link>https://html-in-canvas.page/board/</link>
<guid isPermaLink="true">https://html-in-canvas.page/board/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>iframe</category>
<category>pinch zoom</category>
<description>A canvas you can zoom and pan where every tile is a working document: notes, a spreadsheet, a sketch pad and whole pages in iframes. Text is rasterised again at each zoom level.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/board/"><img src="https://html-in-canvas.page/board/social.jpg" width="1200" height="630" alt="The page &quot;Infinite board of live pages&quot;"></a></p>
<p><strong>Question:</strong> Can a zoomable board of live documents be built with 2D <code>drawElementImage()</code> only, with text rasterised again at each zoom level?</p>
<p>
A zoomable, pannable canvas where every tile is a working document: notes you can type in, a to-do list, a spreadsheet, a sketch pad,
and other pages of this site running in iframes. One <code>drawElementImage()</code> per tile under a zoom transform. The text is
re-rasterised at every zoom level, and clicks, focus and typing go to the elements.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Zoom is free and sharp.</strong> <code>drawElementImage()</code> under a canvas transform replays the element's paint record, so text is re-rasterised at 800% rather than stretched. Hit testing follows the same transform with no extra code.</li>
<li><strong>Iframes are tiles like any other.</strong> A same-origin iframe inside the canvas paints, takes clicks, typing and wheel scrolling at any zoom, and repaints the board when its own content changes. Other HTML-in-canvas pages, a WebGL scene and this board itself all nest.</li>
<li><strong>An iframe swallows input.</strong> Wheel and pointer events inside a frame never reach the board, so each page tile has a cover that hands it the pointer only after a click, the way a map embed does.</li>
<li><strong>Undrawn doesn't mean unclickable.</strong> A tile that is culled or replaced by a placeholder keeps the hit region of its last draw. Park it with <code>updateElementGeometry()</code> or stale tiles catch clicks.</li>
<li><strong>Drawing order decides stacking.</strong> When tiles overlap, the browser hits the one drawn last. <code>z-index</code> on the elements changes nothing, so bringing a tile to the front means drawing it later, and iframes never have to move in the DOM.</li>
<li><strong>Focus can drive the camera.</strong> Tab still walks every control on the board in DOM order, so a <code>focusin</code> listener that pans to the focused tile lets the keyboard reach every tile.</li>
<li><strong>Semantic zoom is a draw decision.</strong> Below a threshold a tile is drawn as a labelled rectangle instead of its DOM. It stays in the document, findable and focusable; focusing it zooms back in.</li>
</ul>
<p><a href="https://html-in-canvas.page/board/">Open Infinite board of live pages</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Element capture</title>
<link>https://html-in-canvas.page/capture/</link>
<guid isPermaLink="true">https://html-in-canvas.page/capture/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>moveBefore</category>
<category>WebCodecs</category>
<category>print</category>
<category>FileSystemObserver</category>
<description>One call turns any element, or a whole ordinary page, into a PNG, a video or a printed page: captureElement(), capturePage(), exportVideo() with WebCodecs. Also copy as a picture and HTML together, page numbers on a printed capture, and a folder of HTML files rendered to PNG files.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/capture/"><img src="https://html-in-canvas.page/capture/social.jpg" width="1200" height="630" alt="The page &quot;Element capture&quot;"></a></p>
<p><strong>Question:</strong> Can any element be exported as a PNG, a video or a printed page by wrapping it in a canvas for one frame?</p>
<p>
One call turns an ordinary element into pixels:
<code>captureElement(el)</code>, <code>recordElement(el)</code>, <code>exportVideo(el)</code>, <code>printElement(el)</code>, and <code>capturePage()</code> for a whole ordinary page.
The library puts a temporary drawable canvas in the element's place for one frame. I wanted to know what survives that, and the tests below say what does and what doesn't.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The body can be wrapped in a canvas for one frame.</strong> The snapshot is ready in the first rendering update after the canvas goes in: the <code>paint</code> event fires in that same frame, so the only thing to wait for is one frame.</li>
<li><strong>The shadow-root route doesn't move any element.</strong> A shadow root on <code>&lt;body&gt;</code> holding <code>canvas &gt; div[drawable] &gt; slot</code> reprojects every body child without touching the light DOM: no mutation records for the page, selectors like <code>body &gt; main</code> keep matching, focus, caret, iframes and scroll position stay put. Its cost is permanent: a shadow root can't be removed, so body keeps a bare <code>&lt;slot&gt;</code> afterwards and the page can never attach its own.</li>
<li><strong>The move route needs <code>moveBefore()</code>.</strong> With it, moving body's children into a canvas and back keeps focus, caret, form state and iframes alive. With plain <code>append</code> the iframes reload and focus is lost, and taking an iframe out of a canvas in the frame it was drawn crashed the tab.</li>
<li><strong>CSS animations restart</strong> when an element becomes a canvas descendant, on every route. The library reads <code>currentTime</code> before and seeks the restarted animations back.</li>
<li><strong>Fixed and sticky need a stand-in viewport.</strong> A drawable element is a containing block, so fixed elements attach to it. Wrapping the content in a viewport-sized frame with an inner scroller set to the page's scroll offset gives a faithful viewport shot. In a full-page shot fixed elements land at the end of the document and sticky ones at their static position.</li>
<li><strong>Cross-origin iframes come out blank</strong>, by design, and so do cross-origin images without CORS. Same-origin iframes paint.</li>
<li><strong>Video doesn't have to be a screen recording.</strong> <code>exportVideo()</code> pauses the element's animations, steps them one frame at a time and encodes each frame with WebCodecs, so a 60 fps file has all 60 frames a second in the right place on any machine. The WebM container is written by a hundred lines of script.</li>
<li><strong>One clipboard item can hold the picture and the content.</strong> <code>copyElement(el, { html: true })</code> writes <code>image/png</code>, <code>text/html</code> and <code>text/plain</code> together, and <code>navigator.clipboard.read()</code> returns all three. The markup has to be read before the capture starts, because the capture adds temporary attributes to the element.</li>
<li><strong><code>@page</code> margin boxes work for a printed capture.</strong> Chromium 157 keeps all three boxes (<code>@top-center</code>, <code>@bottom-left</code>, <code>@bottom-right</code> with <code>counter(page)</code> and <code>counter(pages)</code>) on the print document.</li>
<li><strong>A folder can be the source and the destination.</strong> <code>FileSystemObserver</code> reported a changed file 2 to 5 ms after the write in the test browser, once per write step. A sandboxed <code>srcdoc</code> iframe is drawn only with <code>allow-same-origin</code>; with a bare <code>sandbox</code> its origin is opaque and the canvas leaves it out.</li>
<li><strong>Open:</strong> the folder picker and <code>FileSystemObserver</code> on Android, and HEVC recording, need a real device. The test browser records VP8, VP9, AV1 and H.264 and has no HEVC encoder.</li>
<li><strong>Output is rasterised again at the new size.</strong> <code>drawElementImage(el, 0, 0, w × 4, h × 4)</code> replays the element's paint record at the new size, so a 4× PNG has sharp text and hairlines, and a printed page does too.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/capture.md">findings/capture.md</a> in the repository.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Wrap an ordinary element in a temporary canvas and snapshot it</td><td>works</td><td>Ready in the first rendering update: the <code>paint</code> event fires in the frame the canvas was inserted. About 10 to 20 ms.</td></tr>
<tr><td>Move the element in with <code>moveBefore()</code></td><td>works</td><td>Focus, caret, typed value, scroll offsets and iframes survive; custom elements get <code>connectedMoveCallback</code>, not disconnect.</td></tr>
<tr><td>CSS animations across the move</td><td>restart</td><td>Becoming a canvas descendant restarts them (attaching a shadow root does too). Reading <code>currentTime</code> before and seeking after hides it.</td></tr>
<tr><td><code>drawElementImage(el, 0, 0, w × 4, h × 4)</code></td><td>works</td><td>Re-rasterized, not upscaled: a 1px line becomes 4 hard pixels. Print-quality output from any element.</td></tr>
<tr><td><code>parent &gt; child</code> selectors during capture</td><td>fails</td><td>The canvas is the element's parent for that frame.</td></tr>
<tr><td>Box-shadow and outline outside the border box</td><td>cut off</td><td><code>drawElementImage</code> draws the border box.</td></tr>
<tr><td>Element already in a drawable 2D canvas</td><td>works</td><td>Borrow that canvas for one synchronous tiled draw with <code>preserveElementGeometry</code>, then restore its pixels.</td></tr>
<tr><td>Element in a worker-owned canvas</td><td>clone only</td><td>No context on the main thread to draw with.</td></tr>
<tr><td>Cross-origin iframe; cross-origin image without CORS</td><td>blank</td><td>Left out by design; the canvas stays readable. With CORS the image paints.</td></tr>
<tr><td><code>canvas.captureStream()</code> + MediaRecorder on the temporary canvas</td><td>works</td><td>The element stays live and clickable while it is recorded.</td></tr>
<tr><td>Printing a page that has a drawable canvas</td><td>works</td><td><code>page.pdf()</code> includes the drawn DOM as a bitmap.</td></tr>
<tr><td>Body shadow root: <code>canvas &gt; div[drawable] &gt; slot</code></td><td>works</td><td>Whole page captured with no light-DOM mutation; selectors, focus, caret, iframes and scroll position untouched. The shadow root cannot be removed afterwards.</td></tr>
<tr><td>Move body's children into a canvas and back (in flow, or a fixed overlay)</td><td>works</td><td>Needs <code>moveBefore()</code>. The page sees mutation records, <code>body &gt; x</code> selectors stop matching for the frame, and the browser scrolls when the focused element moves back (restored).</td></tr>
<tr><td>Body already has an open shadow root</td><td>works via move</td><td>Moving the page's own shadow tree into a canvas drops focus, so <code>capturePage()</code> uses the move route instead.</td></tr>
<tr><td>Body has a closed shadow root</td><td>works via move</td><td><code>attachShadow</code> throws; the canvas goes in the light DOM.</td></tr>
<tr><td>Fixed and sticky elements</td><td>works for a viewport shot</td><td>A drawable element is a containing block, so the capture wraps content in a viewport-sized frame with an inner scroller. In a full-page shot fixed elements land at the document end and sticky ones at their static position.</td></tr>
<tr><td>View transition to hide the swap</td><td>fails</td><td><code>paint</code> events do not fire while a view transition holds rendering; the capture waited out the 4s timeout.</td></tr>
<tr><td>Flicker</td><td>none measured</td><td>The snapshot is drawn in the frame the canvas appears. Headless screencasts do not show canvas content, so this still wants an eye: the "Flicker check" button runs 30 captures.</td></tr></tbody></table>
<p>Browser bug: inserting, moving or removing an iframe from inside a <code>paint</code> handler (or a microtask of one) crashes the tab, the same CHECK every time (<code>trap int3</code>, same address). Taking an iframe-holding subtree out of a canvas in that handler does it, and so does appending a new iframe to <code>&lt;body&gt;</code>. The library leaves the paint event with a MessageChannel task before touching the DOM. This is probably the same failure as the <code>adoptNode</code> crash above.</p>
<h3>Video with WebCodecs and print-quality PNG</h3>
<ul><li><strong><code>exportVideo(el, { fps })</code> is frame-exact.</strong> Animations under the element are paused and their <code>currentTime</code> stepped one frame at a time; each frame is drawn in a paint event, wrapped in a <code>VideoFrame</code> and encoded with <code>VideoEncoder</code> (VP9, VP8 fallback). A square animated 160px in 1s is found at x = 0, 80, 144 at 0, 0.5 and 0.9s: exactly where it should be. One rendering update per frame, so 144 frames at 640×360 took 2.4s here.</li>
<li>Setting <code>animation.currentTime</code> and asking for a paint gives that time's pixels in the very next paint event. No extra frame of delay.</li>
<li>Script-driven motion is stepped with an <code>onframe(ms)</code> callback; motion that cannot be stepped uses <code>mode: 'realtime'</code>. <code>encodeFrames(iterable)</code> encodes frames you already have, in the <code>{ time, bitmap }</code> shape <code>&lt;dom-rewind&gt;.frames()</code> yields.</li>
<li><strong>WebM needs no library.</strong> <code>lib/webm-mux.js</code> is about a hundred lines: EBML header, Info with a real duration, one track, Cues before the clusters (so the file seeks), one cluster per key frame. Chrome plays and seeks the result. MP4 would need a larger muxer and H.264, whose software encoder crashed the tab in earlier testing.</li>
<li><code>captureElement(el, { dpi: 300 })</code> re-rasterizes at 3.125× and writes a PNG <code>pHYs</code> chunk, so the file opens at the element's real size in print tools. A 1px rule comes out as 3 crisp pixels.</li></ul>
<h3>Clipboard, print margins, folders</h3>
<p>Measured in headless Chromium 157 on 2026-11-21. Three rows in the page's element tests repeat them.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td><code>copyElement(el, { html: true })</code>: PNG, HTML and text in one <code>ClipboardItem</code></td><td>works</td><td><code>navigator.clipboard.read()</code> returns all three types. The PNG is passed as a promise so the write starts inside the tap.</td></tr>
<tr><td><code>printElement(el, { header, footer })</code> with <code>@page</code> margin boxes</td><td>kept</td><td>The print document's <code>CSSPageRule</code> holds all three boxes, with <code>counter(page)</code> and <code>counter(pages)</code>. Not checked on paper.</td></tr>
<tr><td><code>saveToFolder()</code> into a folder handle, <code>watchFolder()</code> with <code>FileSystemObserver</code></td><td>works</td><td>Run on the origin private file system, which has the same handle API. A change is reported 1 to 5 ms after the write; the tile for a changed HTML file was redrawn 23 ms after the write.</td></tr>
<tr><td>A folder of HTML files as tiles in a canvas, each saved back as a PNG</td><td>works</td><td>Each file is the <code>srcdoc</code> of an <code>&lt;iframe sandbox="allow-same-origin"&gt;</code>.</td></tr></tbody></table>
<ul><li>Read <code>outerHTML</code> before the capture starts. During a capture the element carries a <code>drawable</code> attribute and inline size overrides, and they end up in the copied markup otherwise.</li>
<li>An <code>&lt;iframe sandbox&gt;</code> with no <code>allow-same-origin</code> has an opaque origin and is left out of the canvas picture, like any cross-origin frame.</li>
<li><code>FileSystemObserver</code> reports one record per write step and names the temporary <code>.crswap</code> file too; <code>watchFolder()</code> filters those.</li>
<li>The test browser's <code>MediaRecorder</code> writes VP8, VP9, AV1 and H.264 and has no HEVC encoder. <code>recordFormats()</code> lists what a browser can record.</li>
<li>Not verified: <code>showDirectoryPicker()</code> and <code>FileSystemObserver</code> on Android, and a printed page.</li></ul>
<p><a href="https://html-in-canvas.page/capture/">Open Element capture</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Across origins</title>
<link>https://html-in-canvas.page/cross-origin/</link>
<guid isPermaLink="true">https://html-in-canvas.page/cross-origin/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>postMessage</category>
<category>transferControlToOffscreen</category>
<description>Another origin's DOM shown here as pixels, and this page's DOM drawn by a cross-origin iframe into a canvas that was transferred to it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/cross-origin/"><img src="https://html-in-canvas.page/cross-origin/social.jpg" width="1200" height="630" alt="The page &quot;Across origins&quot;"></a></p>
<p><strong>Question:</strong> What of a drawn element can be sent to another origin, and can a cross-origin frame draw this page's elements into a canvas transferred to it?</p>
<p>
This page and the iframe below are on different origins ( and ).
I tried it in both directions: showing the other origin's DOM here as pixels, and giving this page's DOM to the other origin to draw.
</p>
<h3>Findings</h3>
<ul>
<li><strong>ElementImage and OffscreenCanvas both transfer across origins</strong> with <code>window.postMessage</code> and MessagePorts.</li>
<li><strong>A cross-origin document can render your DOM</strong> if you give it both your canvas (as an OffscreenCanvas) and the snapshots. The pair must match: the snapshot only draws into the canvas it was captured from.</li>
<li><strong>Lending a snapshot means trusting the other origin.</strong> The receiving origin can call <code>getImageData()</code> on what it drew, so it gets the pixels of that element. Only content that is already "read-back allowed" is in there, but it's still your content.</li>
<li><strong>It can't go the other way directly.</strong> A cross-origin iframe placed inside a drawable canvas is painted blank (same-origin iframes paint). To show another origin's DOM, that origin has to cooperate and send pixels, as in part A.</li>
<li><strong>Hit testing still works.</strong> When the other origin draws the snapshot, the element's geometry is updated on this page, so clicks reach the button.</li>
</ul>
<p><a href="https://html-in-canvas.page/cross-origin/">Open Across origins</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Across tabs</title>
<link>https://html-in-canvas.page/cross-tab/</link>
<guid isPermaLink="true">https://html-in-canvas.page/cross-tab/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>MessageChannel</category>
<category>SharedWorker</category>
<category>ImageBitmap</category>
<description>Stream a slot to another tab over a MessagePort brokered by a SharedWorker. Clicks and typing in the other tab are sent back and applied to the element.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/cross-tab/"><img src="https://html-in-canvas.page/cross-tab/social.jpg" width="1200" height="630" alt="The page &quot;Across tabs&quot;"></a></p>
<p><strong>Question:</strong> Can an element be shown and used in another tab?</p>
<p><strong>Short answer:</strong> The page sends <code>ImageBitmap</code> frames over a <code>MessagePort</code>. The other tab sends pointer and key events back, and they're dispatched on the element.</p>
<p>
The widgets below are DOM, slotted into a canvas on this page. Open a viewer and each named slot
is streamed to it over a <code>MessagePort</code>. Click and type in the viewer: the events come back over
the same port and are replayed on the elements here.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The snapshot can't follow the DOM to another tab.</strong> <code>ElementImage</code> is transferable, so <code>postMessage</code> to a popup succeeds, but the popup can't draw it: an ElementImage can only be drawn into the canvas it was captured from (or that canvas's OffscreenCanvas).</li>
<li><strong><code>BroadcastChannel</code> can't carry it.</strong> ElementImage is transferable but not serializable, so <code>structuredClone</code> and BroadcastChannel throw <code>DataCloneError</code>.</li>
<li><strong>Pixels can.</strong> Because HTML-in-canvas strips sensitive content when painting, the canvas isn't tainted and an <code>ImageBitmap</code> of the drawn DOM can go anywhere: MessagePort, BroadcastChannel, popups.</li>
<li><strong>So showing an element in another tab means sending frames and forwarding input.</strong> The viewer updates and takes input, but text in the viewer isn't selectable or accessible; the semantics stay in the source tab.</li>
<li><strong>The source tab has to be rendering.</strong> The <code>paint</code> event runs in the rendering loop, so a hidden or backgrounded source tab stops sending frames. Side-by-side windows (or a popup) work best.</li>
</ul>
<p><a href="https://html-in-canvas.page/cross-tab/">Open Across tabs</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Embeddable live cards</title>
<link>https://html-in-canvas.page/embed/</link>
<guid isPermaLink="true">https://html-in-canvas.page/embed/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>cross-origin</category>
<category>WebGL</category>
<category>ElementImage</category>
<description>A card from another origin that the host page bends with a shader, recolours and resizes. The host can't reach the card's DOM, and the card's buttons work.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/embed/"><img src="https://html-in-canvas.page/embed/social.jpg" width="1200" height="630" alt="The page &quot;Embeddable live cards&quot;"></a></p>
<p><strong>Question:</strong> Can a host page apply a shader to content from another origin without access to its DOM? Two methods are compared.</p>
<p>
The card below is served by a different origin (). This page () can't read or touch its DOM. I wanted to know if it could still bend the card, recolour it and resize it with the buttons working. I found two ways, and each costs something different.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Sending pictures and forwarding input (A)</strong> lets the host put the card anywhere: outside the frame's box, through a shader, in 3D. The cost is that the host's copy is a picture. Semantics have to be rebuilt from the element map, and the card must trust the host with its pixels.</li>
<li><strong>Lending the canvas (B)</strong> leaves hit testing, focus, selection and accessibility to the browser, so there's no input code. The cost is that the drawing stays inside the frame's rectangle.</li>
<li><strong>The card has to agree to be restyled.</strong> The host can recolour pixels by itself. Changing fonts, the radius or the width only happens because the card accepts a short list of custom properties, so the card decides what is allowed.</li>
<li><strong>In B the host decides where the embed can be clicked.</strong> Hit testing follows the last <code>drawElementImage()</code> call, and the host makes that call. An embed that lends its canvas is trusting the host not to slide its buttons under the user's pointer.</li>
<li><strong>The embed has to opt in either way.</strong> A cross-origin frame placed inside the host's own drawable canvas paints blank, so a host can't do any of this to an embed that doesn't cooperate.</li>
</ul>
<p><a href="https://html-in-canvas.page/embed/">Open Embeddable live cards</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A lens over live DOM</title>
<link>https://html-in-canvas.page/lens/</link>
<guid isPermaLink="true">https://html-in-canvas.page/lens/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>drawElementImage</category>
<category>WebGL</category>
<category>touch</category>
<description>Fifteen lenses over ordinary markup: a flat magnifier, a ray-traced glass lens, fisheye, water drop, x-ray, black hole, a fiery eye and more. Each one is one magnified draw and one shader, so text stays sharp and you can click and type through the lens.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/lens/"><img src="https://html-in-canvas.page/lens/social.jpg" width="1200" height="630" alt="The page &quot;A lens over live DOM&quot;"></a></p>
<p><strong>Question:</strong> Can live DOM be magnified and distorted without blur while clicks and typing pass through the lens?</p>
<p>
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.
</p>
<h3>How it works</h3>
<ul>
<li><strong>The content is slotted.</strong> Your markup stays a child of <code>&lt;dom-lens&gt;</code>. A shadow root holds a canvas with one drawable wrapper around a <code>&lt;slot&gt;</code>, sized to the content.</li>
<li><strong>One magnified draw.</strong> <code>drawElementImage()</code> replays the element's paint record, so drawing it scaled re-rasterizes text and vectors. Each frame the square of page under the lens is drawn once, clipped, at the lens's magnification, into a patch of the same canvas.</li>
<li><strong>One shader.</strong> The patch is copied into a texture (<code>copyExternalImageToTexture()</code> on WebGPU, <code>texImage2D()</code> on WebGL) and a fragment shader, written in both WGSL and GLSL, decides, for every pixel of the lens, which point of the patch to show and what to do to its colour. The result is drawn back with <code>drawImage()</code>. All the lenses share one device or context. Then the patch is painted over with the page at rest, clipped to that neighbourhood, so the rest of the canvas is never redrawn while the lens moves.</li>
<li><strong>Real glass</strong> is ray traced: a ray enters the top spherical face, bends by Snell's law, crosses the glass, bends again leaving the bottom face and runs on to the page. Red, green and blue use slightly different refractive indices, which gives the colour fringes, and the edge distortion is the spherical aberration every simple lens has. The zoom slider moves the lens nearer to or further from the page.</li>
<li><strong>Fisheye</strong> is the same pipeline with a smooth radial mapping. <strong>Black hole</strong> uses the point-mass lens equation, so the page forms an Einstein ring. <strong>Water drop</strong> refracts through a spherical cap with a travelling ripple.</li>
<li><strong>X-ray:</strong> the layout box of every element is outlined onto the patch (interactive ones in amber) before the shader runs. It works like a DevTools overlay that you point at part of the page.</li>
<li><strong>Hit testing:</strong> the pointer is the fixed point of the magnification, so the element under the cursor is the one you see there. For a pinned lens the element's geometry is switched to the magnified transform while the pointer is inside it.</li>
<li><strong>Routes.</strong> WebGPU is used when it has a real (not software) adapter and passes a self-test, then WebGL 2, then plain 2D. <code>pipeline="webgpu|webgl|2d"</code> names one by hand. On the 2D route the magnifier and x-ray are two plain draws and the fisheye falls back to the triangle mesh.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/lens.md">findings/lens.md</a> in the repository.</p>
<p>Paul found the fisheye "super slow" on his phone. It was a polar mesh of clipped triangles, one <code>drawElementImage()</code> per triangle: 60 to 70 draws a frame while moving (sized to a 14ms budget) and 199 at rest, on top of a full-canvas redraw for every pointer move.</p>
<p>Every lens is now the same four steps: draw the square of page under the lens once, clipped, at the lens's magnification, into a patch of the element's own canvas; copy the patch to a texture on one shared WebGL context; run the lens's fragment shader; <code>drawImage()</code> the result back and repaint only the patch and the old lens position with the page at rest. Two paint-record replays, two copies and one shader pass per frame, whatever the lens does.</p>
<p>Measured in headless Chromium 157 as a phone (412px wide, <code>--force-device-scale-factor=2.625</code>, <code>viewport: null</code>, CPU 4× slower, lens radius 80, zoom 3, lens swept across the card). The test machine has no GPU, so rasterization, the copies and the shader all run in software; a real phone GPU should do relatively better on the new route, and only a phone can say by how much. The page has a "Measure on this device" button for that.</p>
<table><thead><tr><th>Route</th><th>ms per frame</th><th>worst 5%</th><th>draws per frame</th></tr></thead><tbody><tr><td>Fisheye, old mesh</td><td>254</td><td>567</td><td>63 moving, 199 at rest</td></tr>
<tr><td>Fisheye, shader, full-size patch every frame</td><td>115</td><td>167</td><td>2</td></tr>
<tr><td>Fisheye, shader, patch sized to the frame rate</td><td>32</td><td>50</td><td>2</td></tr>
<tr><td>Magnifier, old (full canvas redraw)</td><td>62</td><td>83</td><td>2</td></tr>
<tr><td>Magnifier, shader route (redraws the lens's neighbourhood only)</td><td>26</td><td>33</td><td>2</td></tr>
<tr><td>Real glass (three ray traces per pixel)</td><td>38</td><td>50</td><td>2</td></tr>
<tr><td>Black hole</td><td>35</td><td>50</td><td>2</td></tr></tbody></table>
<p>Without CPU throttling the same sweep runs at 59 frames a second for the shader fisheye and 16 for the mesh.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Keep text sharp through a shader</td><td>works</td><td>The patch is rasterized at the lens's zoom by <code>drawElementImage()</code>, so the shader samples real pixels: 0.17 soft pixels per ink pixel against 3.86 for a stretched bitmap at zoom 6. The lens is drawn on whole device pixels and the patch has an even size, so at 1:1 texels land on pixels.</td></tr>
<tr><td>Use the element's own canvas as scratch space</td><td>works</td><td>An element image only draws into its own canvas, so the patch borrows a square near the lens and is painted over in the same task. Nothing in between is ever presented.</td></tr>
<tr><td>Copy a sub-rectangle of a 2D canvas into a texture</td><td>works</td><td><code>texImage2D(target, 0, RGBA, w, h, 0, RGBA, UNSIGNED_BYTE, canvas)</code> with <code>UNPACK_SKIP_PIXELS</code> / <code>UNPACK_SKIP_ROWS</code>. Same speed here as going through a small 2D canvas first (<code>copy="scratch"</code>); the speed test runs both because a phone may differ.</td></tr>
<tr><td>One WebGL context for every lens on the page</td><td>works</td><td>Shaders are compiled on first use and the canvas only grows. A lens that just animates (ripples, the black hole's glow) reuses the texture if it was the last to upload.</td></tr>
<tr><td>Cost per frame</td><td>scales with patch pixels</td><td>A fisheye at zoom 3 needs a patch three times the lens's width for a sharp centre: 1262px for an 80px lens at 2.625×. In software that was 70ms of the frame; mipmaps were only 9ms of it.</td></tr>
<tr><td>Draw the patch smaller while the lens moves</td><td>works</td><td>The element times its own frames. Over 26ms it steps the patch down (1.5×, 1×, 0.6× the lens size) and redraws at full size 140ms after the lens stops. A run of fast frames steps it back up, and each relapse doubles the run needed.</td></tr>
<tr><td>A physically modelled magnifying glass</td><td>works</td><td>A biconvex lens of two spherical caps, ray traced per pixel with Snell's law at both faces, once per colour channel with indices 1.508, 1.520 and 1.534. Edge distortion is real spherical aberration; the zoom slider solves for the lens's height above the page from a paraxial ray.</td></tr>
<tr><td>Gravitational lens</td><td>works</td><td>The point-mass lens equation β = θ − θE²/θ. Negative β samples the far side, which gives the second image inside the Einstein ring for free.</td></tr>
<tr><td>A lens that burns the page's own letters (the fiery eye)</td><td>works</td><td>Driven by the sampled page, not painted over it: ink is found from luminance, the page is pushed outward from the eye and stretched towards the rim, each glyph throws a flame (six samples back towards the centre), ink goes from soot to ember to white hot and crumbles against a noise threshold, and the lens ends in a ragged, glowing burn edge with sparks. The element passes the shader an eased direction (travel, or the pointer when pinned) for the pupil. Still two draws.</td></tr>
<tr><td>WebGPU route for the lenses</td><td>works, picked automatically</td><td>All 15 lenses are also written in WGSL (<code>lib/lens-gpu.js</code>). <code>queue.copyExternalImageToTexture({ source: canvas2d, origin }, …)</code> takes the patch straight out of the 2D canvas, a blit pipeline builds six mip levels, one render pass draws the lens into a shared WebGPU canvas and <code>drawImage()</code> copies it back. Compared with WebGL by reading the texture back: mean difference under 3 levels of 255 for every lens.</td></tr>
<tr><td><code>drawElementImageToTexture()</code> for the lens</td><td>not used</td><td>It draws the element at its own size. The lens needs the patch re-rasterized at the lens's zoom, which only the 2D context's transform gives, so both GPU routes start from the 2D patch.</td></tr>
<tr><td>Choosing WebGPU safely</td><td>works</td><td><code>shared/backend.js</code>: needs an adapter that is not a software one, then a self-test (clear a WebGPU canvas, <code>drawImage()</code> it to 2D, read the pixel). The headless test browser has no adapter by default and only SwiftShader with flags, so it always falls to WebGL; a dying WebGPU device takes WebGL contexts with it, which is why the test is strict.</td></tr>
<tr><td>X-ray overlay without <code>ctx.filter</code></td><td>works</td><td><code>difference</code>, <code>color</code> and a dim fill on the patch replace <code>grayscale() invert() sepia() hue-rotate()</code>; the element boxes are drawn onto the patch before the shader.</td></tr>
<tr><td><code>getImageData()</code> on the demo's canvas from a check</td><td>avoided</td><td>A full-canvas readback can move a 2D canvas off the GPU, which would turn both copies into readbacks. The "still drawn" check reads a 160px copy instead.</td></tr></tbody></table>
<p>Not verified here: frame times on a real phone GPU, and whether Chrome on Android keeps the canvas-to-texture copy on the GPU for a sub-rectangle. The WebGPU route has only been checked by texture readback on a software adapter: presenting it on screen, and its speed against WebGL, need a real device (the speed test on the page times both).</p>
<p><a href="https://html-in-canvas.page/lens/">Open A lens over live DOM</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>OffscreenCanvas</title>
<link>https://html-in-canvas.page/offscreen/</link>
<guid isPermaLink="true">https://html-in-canvas.page/offscreen/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>worker</category>
<category>captureElementImage</category>
<description>Transfer ElementImage snapshots to a worker that keeps animating while the main thread is blocked. The page also has a magnifier drawn the same way.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/offscreen/"><img src="https://html-in-canvas.page/offscreen/social.jpg" width="1200" height="630" alt="The page &quot;OffscreenCanvas&quot;"></a></p>
<p><strong>Question:</strong> Can a worker draw DOM elements while the main thread is blocked?</p>
<p><strong>Short answer:</strong> An <code>ElementImage</code> transfers to a worker. It draws only into its source canvas.</p>
<p>
<code>&lt;canvas-slot worker="./renderer.js"&gt;</code> hands its canvas to a worker. On each <code>paint</code> the main thread captures
the slotted elements with <code>captureElementImage()</code> and transfers the <code>ElementImage</code> snapshots. The worker animates them
with its own <code>requestAnimationFrame</code>.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Worker rendering works</strong> with the transferred canvas: <code>captureElementImage()</code> → <code>postMessage(…, [img])</code> → <code>drawElementImage(img)</code> on the OffscreenCanvas, and a snapshot can be redrawn every frame until it's replaced or closed.</li>
<li><strong>Snapshots are tied to their canvas.</strong> A new <code>OffscreenCanvas()</code>, or any canvas other than the source (or its transferred OffscreenCanvas), throws "The source was captured from a different canvas". To show DOM in a second canvas you copy pixels (<code>drawImage(sourceCanvas)</code>), which loses interactivity.</li>
<li><strong>The worker can't make new snapshots.</strong> Only the main thread's rendering update produces them, so a blocked main thread means motion continues but content freezes.</li>
<li><strong>Hit testing follows the worker.</strong> Worker-side draws update geometry asynchronously and fire <code>elementgeometryupdate</code> on the canvas element.</li>
<li><strong>The source canvas must render.</strong> <code>display: none</code> and <code>visibility: hidden</code> canvases never record a snapshot ("No cached paint record"), and a canvas positioned far off-screen is culled (transparent). A canvas that is visible with <code>opacity: 0</code> does work, so that is the way to hide a source canvas.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/offscreen.md">findings/offscreen.md</a> in the repository.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Transfer ElementImage to a worker, draw into the canvas's transferred OffscreenCanvas</td><td>works</td><td>The explainer's pattern.</td></tr>
<tr><td>Redraw one ElementImage for many frames</td><td>works</td><td>Until <code>close()</code>.</td></tr>
<tr><td>Draw an ElementImage into any other canvas (new OffscreenCanvas, second canvas, another document)</td><td>fails</td><td>"The source was captured from a different canvas." Snapshots are bound to their source canvas.</td></tr>
<tr><td><code>structuredClone(ElementImage)</code>, BroadcastChannel</td><td>fails</td><td>Transferable, not serializable.</td></tr>
<tr><td>Worker keeps animating while the main thread is blocked</td><td>works</td><td>But snapshots stop updating: only the main thread's rendering update makes them.</td></tr>
<tr><td>Worker draws update main-thread hit testing</td><td>works</td><td>Batched; <code>elementgeometryupdate</code> fires on the canvas.</td></tr>
<tr><td>Read back pixels of drawn DOM (<code>getImageData</code>, <code>createImageBitmap</code>)</td><td>works</td><td>"Read-back-allowed rendering": sensitive content is never painted, so the canvas is not tainted.</td></tr>
<tr><td>Source canvas with <code>display: none</code> or <code>visibility: hidden</code></td><td>fails</td><td>No paint record is made.</td></tr>
<tr><td>Source canvas far off-screen</td><td>draws transparent</td><td>Culled.</td></tr>
<tr><td>Source canvas at <code>opacity: 0</code></td><td>works</td><td>Usable as a hidden source.</td></tr></tbody></table>
<p><a href="https://html-in-canvas.page/offscreen/">Open OffscreenCanvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Typography as particles</title>
<link>https://html-in-canvas.page/particles/</link>
<guid isPermaLink="true">https://html-in-canvas.page/particles/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Range rects</category>
<category>WebGL instancing</category>
<description>A paragraph's letters fly apart as particles and come back. The paragraph is never split into spans, so you can still select it, search for it, follow its link and edit it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/particles/"><img src="https://html-in-canvas.page/particles/social.jpg" width="1200" height="630" alt="The page &quot;Typography as particles&quot;"></a></p>
<p><strong>Question:</strong> Can each glyph of a paragraph be drawn separately while the paragraph stays selectable, searchable and editable?</p>
<p>
Every letter below is a particle, and the paragraph is still one ordinary block of HTML that the canvas draws in pieces. I wanted to see if the text would survive that. Blow it apart, then select it, search for it, follow the link or edit the paragraph.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The text is never split up.</strong> <code>Range.getClientRects()</code> gives a rectangle per grapheme without touching the markup, and each particle is that rectangle cut from one picture of the whole block. Kerning, ligatures, emoji sequences, links and the accessibility tree are untouched.</li>
<li><strong>First try, 2D: it worked and it was too slow.</strong> <code>drawElementImage(el, sx, sy, sw, sh, dx, dy, dw, dh)</code> cuts a glyph out directly and is quick while glyphs stay upright. Give each glyph its own angle and every draw re-rasterises text at that angle; a thousand draws took over a second here.</li>
<li><strong>Second try, WebGL: one texture, one draw call.</strong> <code>texElementSubImage2D</code> uploads the block when the browser repaints it (the <code>paint</code> event says when), and the glyphs are instanced quads. Fast, but on an Android phone the canvas came out as a solid white block once the letters started moving.</li>
<li><strong>Fourth, where it works: WebGPU.</strong> The same instanced quads in WGSL, with <code>queue.drawElementImageToTexture()</code> for the block. It's picked when the browser has a real WebGPU adapter that passes a self-test and accepts the first frame; otherwise the page uses the 2D renderer below and the line under the renderer menu says why.</li>
<li><strong>Third try, the fallback: 2D with a bitmap atlas.</strong> Draw the block into the 2D canvas, copy it with <code>createImageBitmap</code>, clear, and draw each glyph with <code>drawImage</code> from the copy, all inside one <code>paint</code> handler so the intermediate picture never reaches the screen. Rotation is cheap again because the pieces are pixels. At rest the block is one <code>drawElementImage</code>, so the text is sharp.</li>
<li><strong>When the canvas fails, the element shows plain HTML.</strong> If the context is lost the element lifts its children out of the canvas and shows them as plain HTML until the context returns. A live test reads the canvas back and fails if it's blank or mostly solid.</li>
<li><strong>The selection is part of the picture.</strong> Selected glyphs carry their highlight when they fly. <code>selectionchange</code> plus <code>Range.isPointInRange</code> tells the element which particles are selected, so a selection or a <code>window.find()</code> match can drive the motion.</li>
<li><strong>Interaction stays where the text rests.</strong> The element's hit box is pinned to the home position with <code>updateElementGeometry</code>, so selecting, clicking the link and placing the caret work there even mid-explosion. </li>
<li><strong>A letter in the air can be pointed at, one pointer at a time.</strong> One element has one hit box, so the box follows the pointer: the letter under it is found from the particle list, and the whole block is placed with <code>updateElementGeometry</code> so that letter's home sits exactly under the pointer, turn included. Hover, the caret and clicks then reach the link or paragraph the letter belongs to. A tap has no pointer move before it, so its click is aimed again and re-sent. Letters that have left the canvas margin aren't drawn and can't be hit.</li>
<li><strong>The browser remembers what was at a point.</strong> After <code>updateElementGeometry</code> moves a box, <code>elementFromPoint</code> (and a click) at a point it has already been asked about still gives the old answer until something in the DOM changes. Toggling one attribute when the box moves clears it.</li>
<li><strong>One drawable span per letter does get a hit box per letter,</strong> and inline spans nearly keep the shaping, but it puts an element around every character and each one is a separate draw.</li>
<li><strong>I don't know yet</strong> whether the browser's own find-in-page highlight is painted into the element's picture. <code>window.find()</code> works and selects the match; the yellow find bar highlight needs a person at a real browser.</li>
</ul>
<p><a href="https://html-in-canvas.page/particles/">Open Typography as particles</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Performance wall</title>
<link>https://html-in-canvas.page/perf/</link>
<guid isPermaLink="true">https://html-in-canvas.page/perf/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>requestPaint</category>
<category>worker</category>
<category>Element Timing</category>
<category>Long Animation Frames</category>
<description>How many live elements a canvas can carry before frames drop, as plain DOM, a 2D canvas and a worker, measured on your device. Also the delay from a DOM change to the frame that shows it, and where a long frame spends its time.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/perf/"><img src="https://html-in-canvas.page/perf/social.jpg" width="1200" height="630" alt="The page &quot;Performance wall&quot;"></a></p>
<p><strong>Question:</strong> How many elements can a canvas draw per frame on your device, compared with plain DOM and with a worker?</p>
<p>
Each row keeps adding elements, all moving every frame, until the frame rate drops. The same scene is run as plain DOM with CSS transforms,
as a 2D canvas drawing every element with <code>drawElementImage</code>, and as a worker drawing transferred <code>ElementImage</code> snapshots.
The numbers are measured on your device when you press Run.
</p>
<h3>Findings</h3>
<ul>
<li><strong>A 2D canvas adds no frame of delay.</strong> In Chromium 157 the <code>paint</code> event that draws a change runs in the same frame that paints the changed element, before that frame is presented.</li>
<li><strong>Element Timing doesn't tell you the canvas drew anything.</strong> An entry with a <code>presentationTime</code> arrives for a canvas child even when the paint handler never draws it. The time is when the element's picture was painted.</li>
<li><strong>A worker canvas draws the snapshot within a few milliseconds.</strong> The snapshot is taken in the paint event of the same frame as the change and the worker draws it on its next frame: a median of 3 ms after the change in the test browser. When the worker's frame reaches the screen can't be read from the page.</li>
<li><strong>The canvas's extra cost in a long frame comes after the main thread.</strong> With a grid of 16,000 cells, the main-thread part of the frame was 115 ms as plain DOM and 108 ms in a canvas. The time from the end of the frame to its presentation was 4 ms as plain DOM and 61 ms in a canvas. <code>drawElementImage()</code> itself took 3.8 ms.</li>
<li><strong>The <code>paint</code> handler isn't listed in a long frame's <code>scripts</code>.</strong> Only the <code>requestAnimationFrame</code> callback is.</li>
<li><strong>Open:</strong> the numbers above are from a headless desktop browser with software rendering. A phone's numbers come from the two buttons. Chromium 157 has no separate style and layout durations on the entry; the table shows them when the browser provides them.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/perf.md">findings/perf.md</a> in the repository.</p>
<p>The page ramps 10 to 1,600 moving elements per renderer and reports where the frame rate falls below 90% of the display's refresh. Numbers from headless Chromium use software rendering and only show the shape; run it on real hardware for the wall.</p>
<ul><li>Script is not the limit. A <code>drawElementImage</code> call costs about 7 µs, so 200 cards is roughly 1 ms of a frame. Rasterising and compositing run out first.</li>
<li>In software rendering the 2D canvas carried more moving cards (200 at 60 fps) than the same cards as individually composited DOM layers (100).</li>
<li>A worker holding <code>ElementImage</code> snapshots costs the main thread nothing per frame when content is static. With the main thread blocked 40 ms per frame, a main-thread canvas drops to 23 fps and the worker stays at 60 fps (content updates at the main thread's rate, motion stays smooth).</li>
<li>The worker has no advantage when every element changes every frame: each one needs a fresh snapshot captured on the main thread.</li></ul>
<h3>Latency and long frames</h3>
<p>Measured in headless Chromium 157 (software rendering, phone-size viewport) on 2026-11-21. The page measures the browser it runs in from two buttons.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>DOM change to presentation, plain DOM</td><td>4 ms median</td><td><code>presentationTime</code> of the new element's Element Timing entry.</td></tr>
<tr><td>The same change on a child of a 2D canvas</td><td>5 ms median, same frame</td><td>The <code>paint</code> event ran 2 ms after the change and before the frame was presented, in 8 of 8 samples.</td></tr>
<tr><td>Element Timing for a canvas child the canvas never draws</td><td>an entry arrives</td><td><code>presentationTime</code> is when the element's picture was painted, not when a canvas showed it. This answers the open question in the plan.</td></tr>
<tr><td>Worker canvas: change to the worker's <code>drawElementImage()</code></td><td>3 ms median</td><td>Snapshot in the paint event of the same frame, drawn on the worker's next frame. Presentation of the worker's frame is not observable.</td></tr>
<tr><td>Long frame, 16,000 cells rewritten per frame, plain DOM</td><td>115 ms on the main thread, 4 ms to presentation</td><td>From <code>long-animation-frame</code> entries.</td></tr>
<tr><td>The same grid in a 2D canvas</td><td>108 ms on the main thread, 61 ms to presentation</td><td>The canvas's cost is after the main thread. <code>drawElementImage()</code> took 3.8 ms.</td></tr></tbody></table>
<ul><li>The <code>paint</code> handler does not appear in a long frame's <code>scripts</code> list. Only the <code>requestAnimationFrame</code> callback does.</li>
<li>Chromium 157 entries have <code>renderStart</code>, <code>styleAndLayoutStart</code>, <code>paintTime</code> and <code>presentationTime</code>, and no separate style and layout durations.</li>
<li>Element Timing entries arrive for a fixture that is scrolled out of the viewport.</li>
<li><code>navigator.cpuPerformance</code> is 2 in the test browser (4 cores, 16 GB). <code>lib/device-tier.js</code> maps it to three tiers; the mapping is a guess until it is compared with the wall on real devices.</li></ul>
<p><a href="https://html-in-canvas.page/perf/">Open Performance wall</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Physical UI</title>
<link>https://html-in-canvas.page/physical/</link>
<guid isPermaLink="true">https://html-in-canvas.page/physical/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebGL</category>
<category>Verlet</category>
<category>hit testing</category>
<description>Forms drawn on jelly, cloth and paper meshes that you can drag about. Hit testing follows the mesh, so a click reaches the control drawn under the pointer.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/physical/"><img src="https://html-in-canvas.page/physical/social.jpg" width="1200" height="630" alt="The page &quot;Physical UI&quot;"></a></p>
<p><strong>Question:</strong> Can hit testing stay correct for a form drawn on a mesh that changes shape every frame?</p>
<p>
Three ordinary forms on three materials. Grab one by its background and pull it about, then let go. Press a button
or type and the material takes the hit. Scroll the page and they lag behind. The fields keep focus while this happens, and a click reaches the control that is drawn under the pointer.
</p>
<h3>How it works</h3>
<ul>
<li><strong>The form is a texture on a mesh.</strong> <code>texElementSubImage2D()</code> uploads the element whenever it repaints (typing, focus rings, the caret). The mesh is a grid of point masses joined by distance constraints, stepped with Verlet integration and lit from its surface normals.</li>
<li><strong>It uses WebGPU, then WebGL.</strong> The mesh shader is written in both WGSL and GLSL. The element uses WebGPU when the browser has a real adapter that passes a self-test and accepts the first frame, and WebGL otherwise; the line under the wind control says which and why, and <code>backend="webgpu|webgl"</code> names one by hand. The simulation and hit testing are the same code either way.</li>
<li><strong>Materials are parameters.</strong> Jelly has soft links and a spring to home. Cloth has stiff links, a pinned top edge and a pendulum-like pull home that weakens down the sheet. Paper adds bending links so it folds instead of stretching.</li>
<li><strong>Hit testing uses the triangle under the pointer.</strong> An element only has one transform, and a wobbling mesh isn't one transform. But only the point under the cursor matters, so each frame the element's geometry is set to the affine transform of the mesh triangle the pointer is over. The control you see under the cursor is the one you click.</li>
<li><strong>At rest the mesh is the layout box,</strong> and the simulation stops until you touch it. With reduced motion on, it never moves.</li>
<li><strong>Keyboard and assistive tech see a normal form.</strong> Tab order, labels and focus are untouched; activating a control from the keyboard pushes the material too.</li>
</ul>
<p><a href="https://html-in-canvas.page/physical/">Open Physical UI</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Picture-in-picture for any element</title>
<link>https://html-in-canvas.page/pip/</link>
<guid isPermaLink="true">https://html-in-canvas.page/pip/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>Document PiP</category>
<category>captureStream</category>
<category>Media Session</category>
<description>One call puts any element in a window above your other windows. The element is moved there, shown as a picture that takes input, or sent as a video.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/pip/"><img src="https://html-in-canvas.page/pip/social.jpg" width="1200" height="630" alt="The page &quot;Picture-in-picture for any element&quot;"></a></p>
<p><strong>Question:</strong> Can any element be put in a picture-in-picture window, and does it accept input there? Three methods are compared.</p>
<p>
One call, <code>pipElement(el)</code>, puts any element in a window above your other windows. It can be a timer, a table or one button. Choose how, then press
<em>Float</em> on a specimen, or <em>Pick any element</em> and click anything on this page.
</p>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/cross-context.md">findings/cross-context.md</a> in the repository.</p>
<h3>Picture-in-picture for any element (<code>/pip/</code>, <code>lib/element-pip.js</code>)</h3>
<p><code>pipElement(el, { mode })</code> floats any element. The tear-off demo had these routes for its own widgets; this is the same thing as one call.</p>
<table><thead><tr><th>Mode</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td><code>move</code>: Document PiP, the real element adopted by the floating window</td><td>works</td><td>Needs no HTML-in-canvas. Stylesheets are copied across. While the element is away, <code>document.getElementById()</code> in the page no longer finds it, so page code must hold references.</td></tr>
<tr><td><code>stream</code>: Document PiP showing a live picture, input sent back</td><td>works</td><td>The element stays in the page. Stops updating while the tab is hidden, because <code>paint</code> stops.</td></tr>
<tr><td><code>video</code>: <code>captureStream()</code> into classic video PiP</td><td>works, view only</td><td>Media Session actions can be mapped to buttons inside the element. A fresh surface must paint once before the stream has a size.</td></tr>
<tr><td>Elements that cannot take a shadow root (<code>button</code>, <code>table</code>, <code>form</code>, <code>svg</code>)</td><td>works by wrapping</td><td>They get a <code>&lt;live-region&gt;</code> wrapper. An inline-block holding a canvas sits on the line by its bottom edge, not the text baseline, so the wrapper is lowered by how far the element hung below the baseline. Layout then moves by less than 0.1 px. Table parts (<code>tr</code>, <code>td</code>) cannot be wrapped.</td></tr>
<tr><td>Opening without a click</td><td>refused</td><td><code>NotAllowedError</code>, as it should be.</td></tr></tbody></table>
<p>Device pixels: every <code>drawElementImage()</code> call in these pages passes a width and height. Checked at a real <code>--force-device-scale-factor=1.5</code>: all live checks pass and a click on a streamed picture lands on the right button.</p>
<p><a href="https://html-in-canvas.page/pip/">Open Picture-in-picture for any element</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>&lt;dom-portal&gt;</title>
<link>https://html-in-canvas.page/portal/</link>
<guid isPermaLink="true">https://html-in-canvas.page/portal/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>custom element</category>
<category>updateElementGeometry</category>
<description>A custom element that draws another element a second time, anywhere on the page. You can click and type in either copy.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/portal/"><img src="https://html-in-canvas.page/portal/social.jpg" width="1200" height="630" alt="The page &quot;&lt;dom-portal&gt;&quot;"></a></p>
<p><strong>Question:</strong> Can one element be drawn in two places and take input in both?</p>
<p><strong>Short answer:</strong> An element has one hit-test region. The page moves it to the copy under the pointer.</p>
<p>
The basket on the right is one ordinary <code>&lt;aside id="cart"&gt;</code>. The half-size copy docked at the bottom of the
window is <code>&lt;dom-portal for="cart" scale="0.5"&gt;</code>. It's the same element, drawn a second time. I wanted to know whether both copies could take input. Add something, then change a quantity or type a promo code in <em>either</em> one.
</p>
<h3>How it works</h3>
<ul>
<li><strong>The element is wrapped.</strong> The first portal that points at <code>#cart</code> wraps it in a <code>&lt;dom-portal-source&gt;</code> whose shadow root slots it into a canvas. It isn't copied: your element keeps its listeners and its state, and only its parent changes. You can also write the wrapper yourself.</li>
<li><strong>One canvas spans home and every portal.</strong> An element can only be drawn into its own canvas, so that canvas is stretched over the union of all the places the element appears. It's transparent and ignores pointer events everywhere else. Because it's positioned in the page, scrolling needs no redraw.</li>
<li><strong>An element has one hit-test region.</strong> It can only be in one place at a time, so the page moves it to whichever copy the pointer is over. Focus, typing, selection and the accessibility tree all belong to the one element.</li>
<li><strong>When the union is too big</strong> (a fixed portal far from its source on a long page), the canvas becomes viewport-sized and is redrawn as you scroll. <code>layer="top"</code> puts it in the top layer to escape <code>overflow</code> clipping.</li>
</ul>
<p><a href="https://html-in-canvas.page/portal/">Open &lt;dom-portal&gt;</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Remote component</title>
<link>https://html-in-canvas.page/remote/</link>
<guid isPermaLink="true">https://html-in-canvas.page/remote/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebRTC</category>
<category>Durable Objects</category>
<category>captureStream</category>
<description>Scan a code and one element of the page is streamed to your phone over WebRTC. Taps, typing and choices in native pickers are sent back and applied to the element.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/remote/"><img src="https://html-in-canvas.page/remote/social.jpg" width="1200" height="630" alt="The page &quot;Remote component&quot;"></a></p>
<p><strong>Question:</strong> Can one element be streamed to another device with <code>captureStream()</code> and WebRTC, and take taps and typing from it?</p>
<p>
Scan the code and the panel below is on your phone. It's streamed over WebRTC, and your taps and typing on the phone are sent back and applied to the element on this page. The phone doesn't need HTML-in-canvas, and this one element is all it receives.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Only the source needs HTML-in-canvas.</strong> The viewer is a <code>&lt;video&gt;</code> and a few event listeners, so it runs on any phone.</li>
<li><strong>Controls that open native UI need help.</strong> A <code>&lt;select&gt;</code> popup or an on-screen keyboard belongs to the device in your hand and can't be streamed from the source. The source sends the options and the viewer shows its own native picker; a map of the element's fields tells the viewer when to raise its keyboard.</li>
<li><strong>Pixels carry no roles or names, so the source sends an element map.</strong> Alongside video the source sends roles, names and positions of the interactive elements, read from the DOM. That's enough to rebuild an accessible outline at the far end.</li>
<li><strong>The source tab must stay visible.</strong> A hidden tab stops painting, so the stream freezes. The viewer is told and says so.</li>
<li><strong>STUN is enough for most home networks. It isn't enough for phones on mobile data.</strong> STUN only tells each device its public address. Mobile carriers and many offices give every destination a different port (symmetric NAT), so the two addresses never match up and the connection fails after about 15 seconds. A TURN server relays the packets instead. This site asks <code>/api/x/ice</code> for servers: STUN always, plus Cloudflare Realtime TURN with one-hour credentials when the Worker has a key.</li>
<li><strong>Without TURN the page falls back to a relay.</strong> It sends JPEGs through the room's WebSocket, at one Durable Object message per frame. The viewer switches to it after 7 seconds and moves to video if WebRTC connects later.</li>
<li><strong>A phone needs its errors on the page.</strong> Both ends keep a connection log: the room, the servers offered, each kind of candidate found, the route chosen and every error, with a button to copy it.</li>
</ul>
<p><a href="https://html-in-canvas.page/remote/">Open Remote component</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Shader CSS</title>
<link>https://html-in-canvas.page/shader-css/</link>
<guid isPermaLink="true">https://html-in-canvas.page/shader-css/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>texElementSubImage2D</category>
<category>WebGL</category>
<category>WebGPU</category>
<category>@property</category>
<description>Add fx="ripple" to any element to run it through a fragment shader. CSS custom properties are the uniforms, so transitions animate it.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/shader-css/"><img src="https://html-in-canvas.page/shader-css/social.jpg" width="1200" height="630" alt="The page &quot;Shader CSS&quot;"></a></p>
<p><strong>Question:</strong> Can an HTML attribute draw an element through a fragment shader, with CSS custom properties as the uniforms?</p>
<p>
Add <code>fx="ripple"</code> to an element and it's drawn through a fragment shader. The element is still an element. Its buttons and fields work, and its text can be selected and is in the accessibility tree. CSS custom properties
are the shader's uniforms, so transitions and <code>:hover</code> animate it.
</p>
<h3>How it works</h3>
<ul>
<li><strong>The attribute wraps the element.</strong> A MutationObserver finds <code>[fx]</code> and wraps the element in <code>&lt;fx-surface&gt;</code>, which slots it into a canvas the same size. Remove the attribute and it's unwrapped.</li>
<li><strong>WebGPU first.</strong> When the page has a usable WebGPU device (a real adapter that passes a self-test) and the effect has WGSL source, the canvas is WebGPU: <code>queue.drawElementImageToTexture()</code> uploads the DOM and one render pass draws it. Otherwise the surface uses WebGL, and the line under the cards says why. <code>fx-backend="webgpu|gl"</code> names a route by hand. A custom effect needs a <code>wgsl</code> string beside its <code>glsl</code> to run on WebGPU; the editor above has both. WGSL that doesn't compile is the effect's error, not WebGPU's: the element is drawn unshaded and stays on WebGPU.</li>
<li><strong>Direct backend:</strong> the canvas is WebGL and <code>texElementSubImage2D()</code> uploads the DOM straight into a texture, only when the DOM repaints. It draws one quad with one fragment shader.</li>
<li><strong>Shared backend:</strong> browsers allow about 16 WebGL contexts per page, so after the first eight surfaces the rest use a 2D canvas: <code>drawElementImage()</code>, copy into one shared WebGL context, shade, draw back. That removes the limit on surfaces, at the cost of two extra copies per frame.</li>
<li><strong>CSS sets the shader inputs.</strong> <code>--fx-progress</code> and <code>--fx-amount</code> are registered as numbers, so they transition and animate. The surface samples the computed value each frame and redraws only when a uniform changed.</li>
<li><strong>Input stays at the layout box.</strong> The element's hit-test geometry is its layout box. Displacement is visual only, like a CSS filter. With reduced motion on, time-driven effects hold still.</li>
</ul>
<p><a href="https://html-in-canvas.page/shader-css/">Open Shader CSS</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Just a slot in a canvas</title>
<link>https://html-in-canvas.page/slot-bare/</link>
<guid isPermaLink="true">https://html-in-canvas.page/slot-bare/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>declarative shadow DOM</category>
<category>slot</category>
<description>&lt;slot name&gt; inside &lt;canvas&gt; with declarative shadow DOM and no library, and a shadow root on &lt;body&gt; for slots that take any top-level element of the page.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/slot-bare/"><img src="https://html-in-canvas.page/slot-bare/social.jpg" width="1200" height="630" alt="The page &quot;Just a slot in a canvas&quot;"></a></p>
<p><strong>Question:</strong> Does a <code>&lt;slot&gt;</code> inside a <code>&lt;canvas&gt;</code> project elements with no library?</p>
<p><strong>Short answer:</strong> It does when the canvas is in a shadow root. The page shows three ways to create one.</p>
<p>
This page has no custom element and no library. A <code>&lt;slot name="…"&gt;</code> sits inside the canvas, and ordinary DOM with a matching
<code>slot="…"</code> attribute is projected into it. It turns out a slot only does anything inside a shadow tree, so the canvas has to be in a shadow root. With declarative shadow DOM that is still plain HTML.
</p>
<h3>Findings</h3>
<ul>
<li><strong>A slot in a canvas draws ordinary DOM.</strong> It needs a shadow root and it doesn't need a custom element. With declarative shadow DOM the structure is HTML, and the only script is the <code>paint</code> handler.</li>
<li><strong>A <code>&lt;slot&gt;</code> in the light DOM does nothing.</strong> Outside a shadow tree it's treated like an unknown element, so <code>&lt;canvas&gt;&lt;slot name="x"&gt;</code> in a normal document never picks up <code>slot="x"</code> content from elsewhere. This is the part of my original idea that the platform doesn't support.</li>
<li><strong>Projection is limited to the host's children.</strong> A shadow root on <code>&lt;body&gt;</code> makes the whole page the host, but only for <em>top-level</em> elements. A deeply nested element can't be slotted without moving it.</li>
<li><strong>The slotted element needs <code>drawable</code>,</strong> or the slot needs a drawable wrapper around it in the shadow tree. Several elements can share one slot name and each is drawable on its own.</li>
<li><strong>Slot fallback content draws too,</strong> so a canvas can ship default content that authors override by slotting.</li>
<li><strong>What a native version might look like:</strong> if canvas children could reference elements by id (like <code>popovertarget</code> or <code>aria-owns</code>), any element could be drawn with no shadow root. I think it's worth raising on the WICG repo.</li>
</ul>
<p><a href="https://html-in-canvas.page/slot-bare/">Open Just a slot in a canvas</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>canvas → slot, plain HTML</title>
<link>https://html-in-canvas.page/slot-bare/plain</link>
<guid isPermaLink="true">https://html-in-canvas.page/slot-bare/plain</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>slot</category>
<category>light DOM</category>
<description>The markup with no template and no shadow root: what the browser does natively, and one script that makes it work.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/slot-bare/plain"><img src="https://html-in-canvas.page/slot-bare/plain.social.jpg" width="1200" height="630" alt="The page &quot;canvas → slot, plain HTML&quot;"></a></p>
<p><strong>Question:</strong> What does a <code>&lt;slot&gt;</code> in a light-DOM canvas do with no shadow root?</p>
<p><strong>Short answer:</strong> It projects nothing. A script that moves the matching elements into the canvas makes the markup work.</p>
<p>
The markup you would want to write: a <code>&lt;slot&gt;</code> inside a normal <code>&lt;canvas&gt;</code>, and normal elements elsewhere with a matching
<code>slot</code> attribute. No template, no shadow root, no custom element.
</p>
<p><a href="https://html-in-canvas.page/slot-bare/plain">Open canvas → slot, plain HTML</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Named effects and shader slots</title>
<link>https://html-in-canvas.page/slot-effects/</link>
<guid isPermaLink="true">https://html-in-canvas.page/slot-effects/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>custom element</category>
<category>WebGL</category>
<category>WebGPU</category>
<category>@property</category>
<description>&lt;canvas-slot effect="tilt"&gt; draws each slot as a texture through a named fragment shader, or one you write, with CSS custom properties as its inputs. You don't write a render loop.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/slot-effects/"><img src="https://html-in-canvas.page/slot-effects/social.jpg" width="1200" height="630" alt="The page &quot;Named effects and shader slots&quot;"></a></p>
<p><strong>Question:</strong> Can <code>&lt;canvas-slot&gt;</code> apply a shader to each slot without the page author writing a render loop?</p>
<p>
Add <code>effect="tilt"</code> to <code>&lt;canvas-slot&gt;</code> and you don't write a render loop or any canvas code. Each slot becomes a GPU texture and is drawn through the fragment shader that the effect names. The content is still DOM. Move the pointer over
the cards, click the blue one, type in the field.
</p>
<h3>How it works</h3>
<ul>
<li><strong>The markup doesn't change.</strong> <code>&lt;canvas-slot&gt;</code> without <code>effect</code> behaves as before (2D context, <code>onrender</code>). With it, the canvas gets a WebGPU or WebGL2 context instead and the shader code is loaded on demand.</li>
<li><strong>Each slot is a texture.</strong> <code>texElementSubImage2D()</code> uploads a slot only when the browser says it repainted. One full-canvas quad per slot runs the effect's fragment shader and is blended over the last.</li>
<li><strong>You don't write a render loop.</strong> Slots stack as they do without an effect; set <code>onrender</code> only if you want to place them. The element repaints itself while an effect is moving and sleeps when nothing changes.</li>
<li><strong>CSS sets the shader inputs.</strong> The four <code>--fx-*</code> properties are read from each slotted element every frame while it is on screen. A paint happens only when one changed.</li>
<li><strong>Hit testing follows tilt.</strong> An effect can say where it moves the element (<code>geometry</code>, a <code>DOMMatrix</code>). The shader gets the inverse to sample with, and <code>updateElementGeometry()</code> gets the matrix so clicks, focus rings and selection land on the tilted card. Displacement effects (ripple, curl) are visual only, like a CSS filter.</li>
<li><strong>A canvas keeps its first context type.</strong> Adding or removing <code>effect</code> later swaps in a new canvas and moves the slots across. Content, focus and form state aren't affected, because they were never in the canvas.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/ui-primitives.md">findings/ui-primitives.md</a> in the repository.</p>
<h3>Named effects and shader slots (<code>/slot-effects/</code>)</h3>
<p><code>&lt;canvas-slot effect="tilt"&gt;</code> extends the existing element: without the attribute nothing changes. 15 live checks.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Why</th></tr></thead><tbody><tr><td>Several slots as textures in one WebGL canvas, each through its own shader</td><td>Works</td><td><code>texElementSubImage2D</code> per slot, one blended full-canvas quad each.</td></tr>
<tr><td>Hit testing in shader mode</td><td>Works</td><td>Nothing moves the element for you (there is no <code>drawElementImage</code>), so the renderer calls <code>updateElementGeometry()</code> per slot.</td></tr>
<tr><td><code>canvasTransform</code> with perspective (a 3D <code>DOMMatrix</code>)</td><td>Works</td><td>A tilted card's box narrows from 140px to 79px and <code>elementFromPoint</code> finds its button where the shader drew it. The shader samples through the inverse homography of the same matrix.</td></tr>
<tr><td>CSS transitions and keyframes driving uniforms</td><td>Works</td><td>Registered <code>--fx-*</code> properties are sampled each frame while on screen; a paint is requested only when one changed.</td></tr>
<tr><td>Switching between 2D, WebGL and WebGPU on a live element</td><td>Works, by swapping canvases</td><td>A canvas keeps its first context type. Moving the <code>&lt;slot&gt;</code>s to a new canvas keeps content, focus and typed values.</td></tr>
<tr><td>More shaded elements than WebGL contexts</td><td>Works</td><td>After six, elements keep a 2D canvas and borrow one shared context (draw slot, upload canvas, shade, copy back). Twenty on one page all draw.</td></tr>
<tr><td>WebGPU backend with WGSL effects</td><td>Works off-screen</td><td><code>drawElementImageToTexture</code> into a texture per slot, read back correctly.</td></tr>
<tr><td>WebGPU presenting to the canvas</td><td>Fails in headless software Chrome</td><td>The device is lost on present. The element falls back to WebGL. Not yet tried on a real GPU.</td></tr></tbody></table>
<ul><li>Losing the WebGPU device took every WebGL context <strong>and every large 2D canvas context</strong> on the page with it. Restored contexts came back, but slots drawn into them stayed blank, so the element replaces its canvas instead of waiting for <code>contextrestored</code>.</li>
<li><code>fx</code> and <code>&lt;canvas-slot effect&gt;</code> are one system: <code>effects.js</code> holds the registry, the GLSL/WGSL contract and the CSS properties. <code>fx</code> wraps one element where it sits; <code>&lt;canvas-slot&gt;</code> composes several slots on one canvas.</li></ul>
<p><a href="https://html-in-canvas.page/slot-effects/">Open Named effects and shader slots</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>&lt;slot-view&gt;: portable widgets</title>
<link>https://html-in-canvas.page/slot-view/</link>
<guid isPermaLink="true">https://html-in-canvas.page/slot-view/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>cross-origin</category>
<category>consent</category>
<category>shape-outside</category>
<description>A piece of another site laid out in a line of your text, without an iframe's box. The other site asks the reader before it sends any pixels, and it confirms "Buy now" itself.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/slot-view/"><img src="https://html-in-canvas.page/slot-view/social.jpg" width="1200" height="630" alt="The page &quot;&lt;slot-view&gt;: portable widgets&quot;"></a></p>
<p><strong>Question:</strong> Can an element from another origin be laid out inline at its own size, with a permission prompt on the providing origin?</p>
<p>
The blog post below is on . The price in its second sentence, the basket in its header and the product card its text wraps round are
live pieces of a page on , embedded with <code>&lt;slot-view&gt;</code>. None of them has an iframe's box. Each piece has its own size, sits on the text baseline or floats with its own outline, and you can use it. The shop decides what may leave its page, and it asks you first.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The rectangular box belongs to the iframe.</strong> Once the provider sends pictures, the embed has the size, baseline and outline of the content. It can be inline text, a float with <code>shape-outside</code>, or anything an image can be.</li>
<li><strong>Consent has to happen where the embedder can't reach.</strong> Anything drawn from forwarded pixels and answered by forwarded clicks could be faked by the embedding page. So the question is asked in the provider's real frame, and its Allow button only works while the browser vouches the frame is uncovered and unfaded (<code>IntersectionObserver</code> v2). Small or inline embeds use a window on the provider's origin instead.</li>
<li><strong>Viewing and input are agreed separately.</strong> A public price needs neither prompt nor input. A product card needs both. A purchase needs a click from the reader every time, whatever was agreed.</li>
<li><strong>The embedder can only say no.</strong> It can dismiss a question, give up its permission and ask again. It can't answer yes.</li>
<li><strong>Only the providing page needs HTML-in-canvas.</strong> The embedding page uses a canvas and a hidden frame. Where the provider lacks the API, the same element shows the frame as it is.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/cross-context.md">findings/cross-context.md</a> in the repository.</p>
<h3>Portable widgets (<code>/slot-view/</code>, <code>lib/slot-view.js</code>, <code>lib/slot-provider.js</code>)</h3>
<p><code>&lt;slot-view src name&gt;</code> shows a named piece of another site's page with no iframe box, and the providing site asks the person before anything leaves. The protocol is written down in <code>public/slot-view/PROTOCOL.md</code>.</p>
<table><thead><tr><th>Experiment</th><th>Result</th><th>Notes</th></tr></thead><tbody><tr><td>A cross-origin piece sized by its content, on the text baseline of a sentence</td><td>works</td><td>The provider reports its size and the distance from its first baseline to its bottom edge; the element sets <code>vertical-align</code> to match.</td></tr>
<tr><td>Text wrapping round the piece's outline</td><td>works</td><td><code>shape-outside: url(…)</code> built from the alpha of the frames. The browser lays a shape image out at its own pixel size, so it must be made exactly as many pixels as the element has CSS pixels.</td></tr>
<tr><td>Canvas shrinking to its content</td><td>fails, worked around</td><td>A drawable canvas has no intrinsic width, so <code>width: max-content</code> on its host gives nothing useful. The provider measures the region's one child and sets the width in pixels.</td></tr>
<tr><td>No pixel or element map before consent</td><td>works</td><td>Every protocol message before the grant is refused.</td></tr>
<tr><td>Consent that the embedder cannot fake</td><td>works</td><td>The question is drawn in the provider's real frame, never in the pictures, and only a trusted click answers it. <code>IntersectionObserver</code> v2 (<code>trackVisibility</code>) turns Allow off when the embedder fades, filters or covers the frame.</td></tr>
<tr><td>Consent in a window on the provider's origin (for inline or small embeds)</td><td>works</td><td>The window has to find the waiting frame by itself. <code>opener.frames</code> does not list it, because frames inside a shadow root are left out of <code>window.frames</code>. <code>window.open('', name)</code> with the frame's window name does find it, and same-origin access then works even though the frame's storage is partitioned. A BroadcastChannel is the third try; not needed in Chromium 157.</td></tr>
<tr><td>Consent window opened by the frame itself</td><td>works</td><td>When Allow is switched off, the prompt offers this. The click in the frame gives it the activation to open a window.</td></tr>
<tr><td>View and input granted separately; public view-only slots</td><td>works</td><td>A slot marked <code>slot-consent="none"</code> arrives with no prompt and refuses input.</td></tr>
<tr><td>A guarded button (<code>data-trusted</code>) pressed by forwarded input</td><td>refused, as designed</td><td>The provider asks the person to confirm in its frame or window. The embedder can dismiss the question but cannot answer yes.</td></tr>
<tr><td>Grant remembered per embedding site</td><td>works</td><td>Kept in the frame's <code>localStorage</code>, which the browser already partitions by top-level site.</td></tr>
<tr><td>Theme contract</td><td>works</td><td>Custom properties on the provider's list are applied; the rest are reported back as ignored.</td></tr>
<tr><td>Provider without HTML-in-canvas</td><td>falls back</td><td>The element shows the frame as it is.</td></tr></tbody></table>
<p>Found on the way: <code>serve()</code> dropped a frame that arrived while the previous one was being packed, so a viewer could be left with a blank default-sized first picture until the next change. It now sends once more when that happens, and never sends before the first paint.</p>
<p>Not tested: real cross-site storage partitioning (headless Chromium on two localhost ports is same-site), so the window-name route needs a look on the two deployed Workers. Android opens the consent window as a tab; untested on a real phone.</p>
<p><a href="https://html-in-canvas.page/slot-view/">Open &lt;slot-view&gt;: portable widgets</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>&lt;canvas-slot&gt;</title>
<link>https://html-in-canvas.page/slot/</link>
<guid isPermaLink="true">https://html-in-canvas.page/slot/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>shadow DOM</category>
<category>drawElementImage</category>
<description>A custom element that slots its light-DOM children into a shadow canvas. They're drawn with effects and stay clickable, focusable and typeable.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/slot/"><img src="https://html-in-canvas.page/slot/social.jpg" width="1200" height="630" alt="The page &quot;&lt;canvas-slot&gt;&quot;"></a></p>
<p><strong>Question:</strong> Can a custom element with a canvas in its shadow root draw its light-DOM children and keep them clickable, focusable and typeable?</p>
<p>
HTML-in-canvas only draws elements that are descendants of the <code>&lt;canvas&gt;</code>. A shadow root lets
the canvas live in the shadow tree while your content stays in the light DOM: each named
<code>&lt;slot&gt;</code> inside the canvas pulls in the matching child, and that child is drawn with
<code>drawElementImage()</code>. I didn't want to put all of my content inside the canvas, so this was the first thing I tried. The text below is ordinary DOM. Select it, tab to the input and type.
</p>
<h3>Findings</h3>
<p>Every point links to where it is shown working, or failing, on this page.</p>
<ul>
<li><strong>Slotted light-DOM elements can be drawn directly.</strong> <code>drawElementImage(lightChild)</code> works when the light child is assigned to a slot inside the canvas, because layout and paint use the flat tree. <a href="https://html-in-canvas.page/slot/#hero">Shown in the first demo</a> and in the first row of <a href="https://html-in-canvas.page/slot/#tests">the live table</a>.</li>
<li><strong>The <code>&lt;slot&gt;</code> itself can't be the drawable.</strong> It is <code>display: contents</code>, so it has no box and no paint record ("No cached paint record for element"). Put <code>drawable</code> on the slotted element, or on a real wrapper element in the shadow tree around the slot. <a href="https://html-in-canvas.page/slot/#tests">It fails live in the table</a> ("Mark the &lt;slot&gt; itself drawable").</li>
<li><strong>A shadow wrapper works too.</strong> <code>&lt;div drawable&gt;&lt;slot&gt;&lt;/slot&gt;&lt;/div&gt;</code> inside the canvas draws everything slotted into it as one image, which helps when you can't change the author's markup. <a href="https://html-in-canvas.page/slot/#wrapper">Working demo and full code</a>.</li>
<li><strong>The limit is the host's children.</strong> A slot can only reproject children of its shadow host, so an element elsewhere in the page has to be moved in, or the host made bigger. <a href="https://html-in-canvas.page/slot/#outside">All the routes, with code</a>.</li>
<li><strong>Moving in and out is two lines each way.</strong> Set <code>slot</code> and append to move in; remove <code>slot</code> and append elsewhere to move out. <a href="https://html-in-canvas.page/slot/#reslot">Demo and full code</a>.</li>
<li><strong>Always pass a size to <code>drawElementImage()</code>.</strong> Without one the element is drawn in canvas pixels. On a canvas sized for a high-density screen with <code>ctx.scale(dpr, dpr)</code>, that makes it <code>dpr</code> times too big, and its hit-testing box grows with it. <code>&lt;canvas-slot&gt;</code>'s <code>draw()</code> helper passes the size for you. <a href="https://html-in-canvas.page/slot/#tests">It fails live in the table</a> ("On a sharp canvas…"), which reports the size it got.</li>
<li><strong>Hit testing, focus and selection follow the drawn position</strong>, because <code>drawElementImage</code> updates the element's geometry automatically. Every demo on this page relies on it: the buttons and inputs work where they are drawn. <a href="https://html-in-canvas.page/slot/#tests">Checked live</a> ("Hit testing lands…").</li>
</ul>
<p><a href="https://html-in-canvas.page/slot/">Open &lt;canvas-slot&gt;</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Start here</title>
<link>https://html-in-canvas.page/start/</link>
<guid isPermaLink="true">https://html-in-canvas.page/start/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>content="drawable"</category>
<category>paint</category>
<category>drawElementImage</category>
<description>A tutorial: enable the API, draw one element with a 60-line page, common errors and their fixes, where each API call is used on this site, and a glossary.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/start/"><img src="https://html-in-canvas.page/start/social.jpg" width="1200" height="630" alt="The page &quot;Start here&quot;"></a></p>
<p>
HTML-in-canvas lets a <code>&lt;canvas&gt;</code> draw its descendant elements with <code>drawElementImage()</code>. The
canvas can transform, clip or filter the drawing, or upload it as a WebGL or WebGPU texture. The elements still take
clicks and typing, their text can be selected, and they stay in the accessibility tree. This is the one tutorial on the site. It shows you how to turn the API on and draw one element.
</p>
<p><a href="https://html-in-canvas.page/start/">Open Start here</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Support widget</title>
<link>https://html-in-canvas.page/support/</link>
<guid isPermaLink="true">https://html-in-canvas.page/support/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>co-browsing</category>
<category>Workers AI</category>
<category>redaction</category>
<description>Share one panel of a page with a support agent or an AI model, and not your whole screen. Private fields are blacked out and actions need your approval.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/support/"><img src="https://html-in-canvas.page/support/social.jpg" width="1200" height="630" alt="The page &quot;Support widget&quot;"></a></p>
<p><strong>Question:</strong> Can a page share one element, instead of the screen, with another person or a vision model, with marked fields blacked out before the frame is sent?</p>
<p>
Share one part of a page with a support agent, or with an AI model, instead of your whole screen. Open the widget, click the panel you need
help with, and only that element is sent. Private fields are blacked out, and there's no screen-sharing prompt.
</p>
<h3>How it works</h3>
<ol>
<li><strong>Pick.</strong> Clicking a panel gives that element a shadow root containing a canvas and a slot. Its children stay where they are in the document and are painted through the canvas, which is what makes their pixels available. The panel isn't cloned.</li>
<li><strong>Redact.</strong> Each frame is copied to a second canvas, where anything marked <code>data-private</code> (and every password field) is covered. Only that copy leaves the page. The same rule withholds their values from the element list.</li>
<li><strong>Send pixels and a list of controls.</strong> A person gets video over WebRTC. A model gets a JPEG. Both also get a list of the region's controls, read from the DOM: role, name, value. With that list either of them can say "the Retry payment button" and the page knows which element is meant.</li>
<li><strong>Act with permission.</strong> The agent's pointer is drawn on the canvas for you to see. Clicks and typing from the agent are refused until you allow them. The model can only propose a click or a value; you press the button that makes it happen.</li>
</ol>
<h3>Findings</h3>
<ul>
<li><strong>Element sharing is a different permission model from screen sharing.</strong> The page chooses what can be shared, the user chooses which part, and nothing else is in the frame. Other tabs, notifications and the address bar can't be.</li>
<li><strong>The page can redact, because it knows its own DOM.</strong> A screen recorder sees pixels. This sees elements, so "never send the card number" is a selector.</li>
<li><strong>A model does better with the DOM beside the picture.</strong> The picture shows layout and state; the element list gives exact labels and values and gives the model something to point at and act on.</li>
<li><strong>Any element with a shadow root to spare can be converted in place.</strong> Grid and flex containers need their layout properties copied to the inner box. Elements that already have a shadow root, or can't have one, need a wrapper instead.</li>
<li><strong>The sharing tab must stay visible.</strong> It is the page's own paint that is being sent, so a hidden tab sends nothing.</li>
</ul>
<p><a href="https://html-in-canvas.page/support/">Open Support widget</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Tear-off widgets</title>
<link>https://html-in-canvas.page/tear-off/</link>
<guid isPermaLink="true">https://html-in-canvas.page/tear-off/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>window.open</category>
<category>Picture-in-Picture</category>
<category>BroadcastChannel</category>
<description>Pull a widget out of the page into a popup, an always-on-top window, another tab or another origin. It keeps working there, and what you do to it is applied to the element on this page.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/tear-off/"><img src="https://html-in-canvas.page/tear-off/social.jpg" width="1200" height="630" alt="The page &quot;Tear-off widgets&quot;"></a></p>
<p><strong>Question:</strong> Can a widget move to a popup, an always-on-top window, another tab or another origin and keep working? Four methods are compared.</p>
<p>
Three ordinary widgets. Pull one out of the page into a new window, an always-on-top window, another tab or another origin. It keeps working there, and what you do to it is sent back and applied to the element on this page. Drag a grip ⠿ outside this
window, onto the <a href="https://html-in-canvas.page/tear-off/dock.html">dock tab</a>, or pick a route from the menu.
</p>
<h3>Findings</h3>
<ul>
<li><strong>Interaction does get back to the origin without any window link.</strong> A <code>noopener</code> tab reaches the source over <code>BroadcastChannel</code> (ImageBitmaps clone across it), through a <code>SharedWorker</code> that hands both tabs one end of a <code>MessageChannel</code>, or through the Worker's relay room. Even <code>localStorage</code> events work as a transport.</li>
<li><strong>Across origins with no link, you need a meeting point.</strong> The relay room works anywhere. A frame from the source's origin embedded in the other page can also bridge to <code>BroadcastChannel</code>. Browsers that partition third-party storage are expected to cut that bridge when the two pages are different sites; headless Chromium 157 did not, so check the row above in your own browser.</li>
<li><strong>A scripted <code>about:blank</code> popup needs no messaging.</strong> The opener calls into the popup's document directly and hands it ImageBitmaps by reference.</li>
<li><strong>The source page has to be on screen for streaming.</strong> <code>paint</code> stops when the tab is hidden, so a streamed widget freezes while you are in another tab. Moving the element into a Picture-in-Picture window doesn't have that problem, because the element is then painted by that window.</li>
<li><strong>Video Picture-in-Picture is view only, but not button-less.</strong> Media Session actions show as buttons on the video window, and this page maps them to the widget's own buttons.</li>
</ul>
<p><a href="https://html-in-canvas.page/tear-off/">Open Tear-off widgets</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>A form in a three.js scene</title>
<link>https://html-in-canvas.page/three-form/</link>
<guid isPermaLink="true">https://html-in-canvas.page/three-form/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>three.js</category>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>A laptop screen, a far-away billboard and a curved wall, each showing an HTML document you can type in, tab through and select. It runs on WebGL or WebGPU.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/three-form/"><img src="https://html-in-canvas.page/three-form/social.jpg" width="1200" height="630" alt="The page &quot;A form in a three.js scene&quot;"></a></p>
<p><strong>Question:</strong> Can an HTML form be a three.js texture and keep typing, Tab and text selection on a 3D surface?</p>
<p>
Three HTML documents on three kinds of surface: a laptop screen, a far-away billboard and a curved wall. Type, tab, select text,
drag the slider, scroll the list. They're ordinary DOM elements inside the <code>&lt;canvas&gt;</code>, uploaded as textures on every
<code>paint</code>, and the browser's hit testing follows them around the scene.
</p>
<h3>Findings</h3>
<ul>
<li><strong>The method names changed.</strong> three.js r187 ships <code>HTMLTexture</code>, but it calls <code>gl.texElementImage2D</code> and <code>queue.copyElementImageToTexture</code>. Chromium 157 has <code>texElementSubImage2D</code> and <code>drawElementImageToTexture</code>, so stock three draws nothing until a small shim is installed. <a href="https://html-in-canvas.page/lib/html3d.js"><code>html3d.js</code></a> feature-detects both spellings.</li>
<li><strong>Hit testing needs <code>updateElementGeometry()</code>.</strong> three's <code>InteractionManager</code> positions elements with a CSS <code>matrix3d</code>. In this build a CSS transform on a WebGL-drawn element doesn't make it hit-testable; a perspective <code>DOMMatrix</code> passed to <code>updateElementGeometry()</code> does, and bounding rects, focus rings and the caret follow it.</li>
<li><strong>Curved surfaces work if the geometry follows the pointer.</strong> A rectangle can't be mapped onto a cylinder with one matrix, but a mouse hit test only looks at one point. Raycast, take the triangle's UV Jacobian, and re-place the element on every pointer move.</li>
<li><strong>Occlusion is yours to handle.</strong> The DOM has no idea a drone is in front of the screen. The same raycast parks a hidden surface's geometry off-canvas so clicks can't pass through scene objects.</li>
<li><strong>Touch is the weak spot for curved surfaces.</strong> A tap has no pointer move before it, so the hit test runs against the flat fallback placement. Flat surfaces are exact for touch.</li>
<li><strong>The billboard needs mipmaps.</strong> Uploading into an immutable sRGB texture of the page's own and calling <code>generateMipmap()</code> keeps the billboard readable from across the scene. three's stock path uses a single level.</li>
</ul>
<p><a href="https://html-in-canvas.page/three-form/">Open A form in a three.js scene</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Time scrubber</title>
<link>https://html-in-canvas.page/time-scrubber/</link>
<guid isPermaLink="true">https://html-in-canvas.page/time-scrubber/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>ElementImage</category>
<category>changedElements</category>
<description>A ring buffer of frames of an element. Drag the slider to see earlier frames, leave motion trails, and restore an earlier frame with its form values.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/time-scrubber/"><img src="https://html-in-canvas.page/time-scrubber/social.jpg" width="1200" height="630" alt="The page &quot;Time scrubber&quot;"></a></p>
<p><strong>Question:</strong> Can a page keep past frames of an element and return to an earlier one, form values included?</p>
<p>
A ring buffer of DOM frames. Type in the note, tick some boxes, drag the cards about, then pull the slider back to see the interface as it was.
"Restore this moment" puts the interface back to that frame, with its form values.
</p>
<h3>Findings</h3>
<ul>
<li><strong>An ElementImage is cheap to keep.</strong> It keeps drawing the element as it was when captured, after the element has changed or even left the document, and hundreds can be held at once. The <code>paint</code> event's <code>changedElements</code> says which children need a new one, so an element that is idle or only moving shares one snapshot across frames.</li>
<li><strong>An old frame is a picture.</strong> A snapshot has one method, <code>close()</code>. You can't select its text, query it or lay it out again. So to go back to a frame the page has to keep state next to it (values, checked, open, scroll, app data) and putting it back, which is what <code>restore()</code> does.</li>
<li><strong>Drawing a snapshot moves the live element's hit box</strong> to where the snapshot was drawn. Trails draw the live elements last, and the past is made click-proof while you look at it.</li>
<li><strong>Snapshots still draw after a resize.</strong> Snapshots captured before the canvas changed size still draw, and their default size is recomputed for the new canvas grid.</li>
<li><strong>Snapshots scale like vectors.</strong> An old frame drawn at four times its size is re-rasterised from the recorded paint commands, so text stays sharp where a bitmap of the same frame goes soft.</li>
<li><strong>Alpha, filters and blend modes all apply</strong> to <code>drawElementImage</code>, which is all trails need.</li>
</ul>
<p><a href="https://html-in-canvas.page/time-scrubber/">Open Time scrubber</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Live view transitions</title>
<link>https://html-in-canvas.page/transitions/</link>
<guid isPermaLink="true">https://html-in-canvas.page/transitions/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>texElementSubImage2D</category>
<category>updateElementGeometry</category>
<description>Shatter, fold, burn or morph between two states that are both DOM for the whole transition. You can stop half way and press a button on a shard.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/transitions/"><img src="https://html-in-canvas.page/transitions/social.jpg" width="1200" height="630" alt="The page &quot;Live view transitions&quot;"></a></p>
<p><strong>Question:</strong> Can two states both accept input while a shader blends between them, and which one does a click reach?</p>
<p>
Shatter, fold, burn or morph between two states. A view transition animates screenshots. Here both states are DOM for the whole transition, so a clock keeps ticking on a flying shard, and you can stop half way and press a button on either side.
</p>
<h3>Findings</h3>
<ul>
<li><strong>It uses WebGPU, then WebGL.</strong> Every built-in effect is written in both WGSL and GLSL. The element uses WebGPU when the browser has a real adapter that passes a self-test and accepts the first frame, and WebGL otherwise; the line under the controls says which and why, and <code>backend="webgpu|webgl"</code> names one by hand. A shader effect given only as GLSL (like <em>Yours</em>) moves the element to WebGL.</li>
<li><strong>Both states take input and repaint during the transition.</strong> Whenever the browser repaints a state (the <code>paint</code> event lists which), it's uploaded again with <code>texElementSubImage2D</code>, so CSS animations, typing, checkbox ticks and selection highlights appear on shards, folds and embers as they happen.</li>
<li><strong>The mesh is also used for hit testing.</strong> WebGL draws don't move an element's hit box, so the element keeps the last frame's triangles. On pointer move it finds the triangle under the pointer, works out the affine matrix that maps that piece of the state to the screen, and hands it to <code>updateElementGeometry</code>. You can press a button that is riding a shard.</li>
<li><strong>One element has one hit box.</strong> A shattered state is 100+ pieces but the element can only be in one place, so routing follows the pointer. Two pointers on two shards would disagree. Perspective is approximated per triangle.</li>
<li><strong>Burn is routed per pixel.</strong> The shader's noise is also kept on the CPU, so the pointer goes to the new state where the fire has passed and the old one where it has not.</li>
<li><strong>Your own shader samples both states.</strong> A shader effect is a <code>transition(uv)</code> function with <code>getFromColor</code> and <code>getToColor</code>. The two textures are the two states as the browser painted them this frame, so a shader written for still images runs over an interface that is still changing. A shader has no geometry, so it can bring a small <code>pick()</code> function to say which state owns each point; without one the states swap at half way.</li>
<li><strong>Morph needs no extra snapshots.</strong> Paired elements are sub-rectangles of the two state textures. The hole they leave is filled by smearing the nearest pixels outside it, which is right for flat backgrounds and visible on busy ones.</li>
<li><strong>A state that was never painted has no picture.</strong> A <code>visibility: hidden</code> state can't be uploaded, so the element waits two paints before the first frame. Anything in the top layer (modal dialogs, popovers) isn't part of the state's picture either.</li>
</ul>
<p><a href="https://html-in-canvas.page/transitions/">Open Live view transitions</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>Transport lab</title>
<link>https://html-in-canvas.page/transports/</link>
<guid isPermaLink="true">https://html-in-canvas.page/transports/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>VideoFrame</category>
<category>WebRTC</category>
<category>WebCodecs</category>
<category>WebGL</category>
<description>Nearly fifty routes for getting DOM out of its canvas: snapshots, bitmaps, video frames, streams, WebRTC, codecs, WebGL. Each one is tested in your browser.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/transports/"><img src="https://html-in-canvas.page/transports/social.jpg" width="1200" height="630" alt="The page &quot;Transport lab&quot;"></a></p>
<p><strong>Question:</strong> Which transports can carry drawn DOM to another context? About fifty are tested, with the reason for each failure.</p>
<p>
Every route I could think of for getting DOM out of its canvas and into another context: another canvas, a worker, a cross-origin document. Each row is a test that runs in your browser. The small canvas shows what arrived at the far end, and a row passes only if the pixel read there matches the source element.
</p>
<h3>Findings</h3>
<ul>
<li><strong>An ElementImage isn't an image.</strong> It isn't a <code>CanvasImageSource</code>: <code>drawImage</code>, <code>createImageBitmap</code> and <code>VideoFrame</code> all reject it, and it only draws into its own canvas (2D or WebGL, main thread or worker). Every route out goes through that canvas first.</li>
<li><strong>Fastest way out: a worker that owns the canvas.</strong> Snapshot → worker → <code>drawElementImage</code> → <code>transferToImageBitmap()</code> gives a GPU-backed bitmap per frame with no main-thread rasterization, and from there it can go to any canvas, tab or origin.</li>
<li><strong>Three ways keep the content as DOM:</strong> nest canvases (an inner drawable canvas is itself a drawable element of the outer one), put a same-origin iframe inside the canvas (a whole document reprojected live), or use one page-wide overlay canvas with <code>pointer-events: none</code> so any element can be drawn anywhere while the page stays clickable.</li>
<li><strong>Across origins, send bitmaps or bytes.</strong> <code>VideoFrame</code> and streams of them fail to deserialize in a cross-origin document (a silent <code>messageerror</code>), and <code>MediaStreamTrack</code> doesn't transfer. <code>ImageBitmap</code>, a <code>ReadableStream</code> of ImageBitmaps, Blobs, ArrayBuffers, encoded video chunks and WebRTC all get through.</li>
<li><strong>Hit testing stops at the canvas edge.</strong> <code>updateElementGeometry</code> accepts a transform outside the canvas box, but the element isn't hit-testable there. Interactivity at a remote mirror means forwarding input (as in the cross-tab demo) or making the canvas bigger (the overlay).</li>
<li><strong>Not testable in every environment:</strong> WebGPU needs a GPU adapter, and SharedArrayBuffer needs cross-origin isolation headers, which this site doesn't send yet.</li>
</ul>
<h3>Results table</h3>
<p>From <a href="https://github.com/PaulKinlan/html-in-canvas-demos/blob/main/findings/transports.md">findings/transports.md</a> in the repository.</p>
<p>49 routes tested live. In Chromium 157 headless: 30 work, 15 fail, 4 can't be tested there (no WebGPU adapter, no cross-origin isolation, one crash kept opt-in).</p>
<p>Works:</p>
<ul><li>ElementImage → its own canvas as 2D, as WebGL (<code>texElementSubImage2D</code>, element or ElementImage), on the main thread or in a worker.</li>
<li>Worker owns the canvas, draws the snapshot, then <code>transferToImageBitmap()</code>, <code>createImageBitmap()</code> or <code>new VideoFrame()</code> to send pixels on. A cross-origin frame can do the same and send pixels back.</li>
<li>Nested drawable canvases; a same-origin iframe as a drawable child; a page-wide overlay canvas with <code>pointer-events: none</code> (element hit-testable where drawn, page underneath still clickable).</li>
<li>Pixels: ImageBitmap over MessageChannel, BroadcastChannel, cross-origin postMessage and <code>bitmaprenderer</code>; VideoFrame to a MessageChannel or worker; ArrayBuffer, Blob and data URL routes.</li>
<li>Streams: <code>captureStream()</code> to <code>&lt;video&gt;</code>, MediaStreamTrackProcessor, <code>ReadableStream&lt;VideoFrame&gt;</code> to a worker, <code>ReadableStream&lt;ImageBitmap&gt;</code> to a cross-origin frame, MediaStreamTrackGenerator back into a <code>&lt;video&gt;</code>, WebRTC loopback, VP8 encode → bytes → decode.</li></ul>
<p>Fails:</p>
<ul><li>ElementImage into any other canvas (2D or WebGL), <code>drawImage(ElementImage)</code>, <code>createImageBitmap(ElementImage)</code>, <code>new VideoFrame(ElementImage)</code>, <code>structuredClone</code>.</li>
<li>VideoFrame and <code>ReadableStream&lt;VideoFrame&gt;</code> to a cross-origin document (<code>messageerror</code> / "chunk could not be cloned").</li>
<li>MediaStreamTrack transfer (not transferable in this build).</li>
<li>Sandboxed opaque-origin iframe inside a drawable canvas (blank).</li>
<li>Hit testing outside the canvas box via <code>updateElementGeometry</code>.</li></ul>
<p>Possible browser bug: <code>adoptNode()</code> of a drawable canvas into a same-origin iframe works if the canvas has never painted, and crashes the tab if it has (<code>/transports/crash-adopt.html</code>, button B).</p>
<p><a href="https://html-in-canvas.page/transports/">Open Transport lab</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
<item>
<title>WebXR panels</title>
<link>https://html-in-canvas.page/xr/</link>
<guid isPermaLink="true">https://html-in-canvas.page/xr/</guid>
<pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Paul Kinlan</dc:creator>
<category>WebXR</category>
<category>three.js</category>
<category>synthetic input</category>
<description>HTML panels in a three.js XR scene, with a keyboard that is one of the panels. Controller rays become pointer events on the elements. The page has a desktop preview and a headset emulator.</description>
<content:encoded><![CDATA[<p><a href="https://html-in-canvas.page/xr/"><img src="https://html-in-canvas.page/xr/social.jpg" width="1200" height="630" alt="The page &quot;WebXR panels&quot;"></a></p>
<p><strong>Question:</strong> Can HTML panels be used in WebXR, where there is no mouse? Controller rays are converted to pointer events on the elements.</p>
<p>
A form, a guest book, a diagnostics read-out and a keyboard as panels in a 3D scene. Each one is plain HTML inside the
<code>&lt;canvas&gt;</code>, uploaded as a texture on every <code>paint</code>. On this page you use them with the mouse or a finger.
In a headset there is no mouse, so controller, hand and gaze rays are turned into pointer events on the same elements.
</p>
<h3>Findings</h3>
<ul>
<li><strong>This page stays on WebGL.</strong> The other shader demos here use WebGPU when it works. An immersive session is presented through an <code>XRWebGLLayer</code>, and the WebGPU route into WebXR needs <code>XRGPUBinding</code>, which is missing from the Chrome this was built on (157). So three's <code>WebGLRenderer</code> draws both the page and the headset view.</li>
<li><strong>The texture upload is the same in a headset.</strong> A panel is a mesh with an element texture. Nothing about the upload changes when the same renderer is presenting to a headset.</li>
<li><strong>The input half does not.</strong> Browser hit testing is tied to the page's 2D box, and an immersive session has no pointer over it. Rays have to be turned into events by hand, and synthetic events are untrusted: focus, caret placement, slider drags and <code>&lt;select&gt;</code> all need a hand-written stand-in.</li>
<li><strong><code>elementFromPoint</code> turns a ray into an element.</strong> Lay the elements out flat with <code>updateElementGeometry()</code>, turn the ray's UV hit into a point in that layout, and the browser still answers which element is there, including inside scrollers.</li>
<li><strong>The keyboard is a set of buttons.</strong> Keys that cancel <code>mousedown</code> never take focus, so <code>setRangeText()</code> plus an <code>input</code> event types into whatever field had the caret.</li>
<li><strong>I don't know yet whether <code>paint</code> keeps firing inside a real headset.</strong> The Diagnostics panel counts paint events during the session and falls back to forced uploads if they stop. The emulator can't answer this. It needs a device.</li>
</ul>
<p><a href="https://html-in-canvas.page/xr/">Open WebXR panels</a>. The page draws live HTML in a canvas and runs its checks in your browser, so it needs a Chrome that has the HTML-in-canvas API.</p>]]></content:encoded>
</item>
</channel>
</rss>
