Time scrubber
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.
Note
Stopwatch
0.0
List
More
Open state is kept too.DOM
Show the code recording and scrubbing DOM
- Put anything inside
<dom-rewind>. Each child is recorded.data-xanddata-ysay where it starts. - Seek, replay and restore.
oncaptureandonrestorecarry state that lives in your script (here the stopwatch,sw).timelineis the range input. - Inside the element: keep a snapshot whenever a child repaints.
canvas.captureElementImage(el)returns anElementImage, a frozen picture of the element that can be drawn later. Thepaintevent'schangedElementssays which children need a new one. - Inside the element: draw the past or the present.
drawElementImage()takes an old snapshot or the live element. The live elements are drawn last, because the last draw decides where clicks land. - The whole element.
LIVE
Use it
<script type="module" src="/lib/dom-rewind.js"></script>
<dom-rewind seconds="30" trails="6" style="height: 400px">
<div data-x="20" data-y="20">…any HTML…</div>
</dom-rewind>
<script>
const rw = document.querySelector('dom-rewind');
rw.place(rw.children[0], { x: 120, y: 40, rotate: 0.1 });
rw.seek(2.5); // 2.5 s ago
rw.restore(); // or rw.live()
rw.oncapture = () => appState; // optional: ride along with each frame
rw.onrestore = (state) => { appState = state; };
</script>
Live checks
These run in your browser when this section is on screen, on the small fixtures in the box below. They don't touch the desk above.
test rig
A
Findings
- An ElementImage is cheap to keep. 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
paintevent'schangedElementssays which children need a new one, so an element that is idle or only moving shares one snapshot across frames. - An old frame is a picture. A snapshot has one method,
close(). 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 whatrestore()does. - Drawing a snapshot moves the live element's hit box to where the snapshot was drawn. Trails draw the live elements last, and the past is made click-proof while you look at it.
- Snapshots still draw after a resize. Snapshots captured before the canvas changed size still draw, and their default size is recomputed for the new canvas grid.
- Snapshots scale like vectors. 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.
- Alpha, filters and blend modes all apply to
drawElementImage, which is all trails need.