Origami boarding pass and tear-off stub
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 /accordion/ and the paper peel in /view-source/, 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 Tear here tab to unzip the stub.
Flat and untorn. Controls use one unclipped five-argument draw per half.
Show the code two drawable halves, 4-panel origami fold, serrated tear, and hit-box restore
- The markup. One
<canvas content="drawable" layoutsubtree>holding two siblingdrawablehalves:#pass-mainand#pass-stub. - Origami accordion fold. Four hinged panels drawn with nine-argument
drawElementImage(), alternating shear, cosine foreshortening, and crease shading. - Serrated tear and fling. Complementary sawtooth clip paths separate the perforation as you drag, then a damped spring flings the detached stub apart.
- Restoring hit boxes. After sliced or clipped draws, an empty-clip five-argument draw puts each half's hit region back on its full painted box.
- Pointer input. Ignores clicks on form controls so typing and taps keep working, while drags on the handle tear and drags on the paper fold.
- Boarding pass layout. Side-by-side on wide screens, stacked with a horizontal perforation below 540 px, plus a CSS barcode.
How it works
I split the boarding pass into two sibling drawable children inside one 2D canvas: #pass-main and #pass-stub. While the pass is flat and untorn, each half takes one unclipped five-argument drawElementImage(el, x, y, w, h) call right beside its neighbour. That keeps every input, select menu, checkbox, and button aligned to its painted pixels.
When you fold the pass, I slice the combined width (or height on a narrow phone screen) into four hinged panels using nine-argument drawElementImage(source, sx, sy, sw, sh, dx, dy, dw, dh), borrowing the alternating shear idea from /accordion/. 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.
When you drag the Tear here 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 /view-source/ and wallet pass stubs. Once the rip passes 75%, a damped spring flings #pass-stub clear at a slight angle. At the snap point I take one brief captureElementImage() snapshot of the stub for a faint motion trail and call close() as soon as the spring settles, so zero snapshots stay open at rest.
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 drawElementImage() for each half under its current transform (matching the hit-restore pattern in /lib/text-canvas.js) and toggle a data-hit attribute when motion stops so Chromium clears its hit-test cache. Because #pass-main and #pass-stub are separate drawable children, both halves stay interactive after the tear.
Live checks
These run on isolated fixtures in the corner of the window and leave the boarding pass above untouched. Pixel checks copy each fixture canvas with drawImage() into a plain 2D canvas before calling getImageData().
Findings
- Direct inspirations: /accordion/ for sheared-strip folding on a 2D canvas, /view-source/ for tactile paper peeling, and physical tear-off boarding pass stubs from mobile wallet UIs.
- Putting
#pass-mainand#pass-stubas two siblingdrawablechildren avoids the single-element hit-box tradeoff: if the whole ticket were onedrawablenode, 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 Scan stub and Priority boarding while#pass-mainkeeps working separately. - At rest (
fold <= 0.01and untorn), drawing each half with one unclipped five-argumentdrawElementImage()avoids any hit-box shrink from nine-argument slices. - This page hasn't been run in a live browser yet, so every runtime behaviour below is not verified until the checks run in Chromium 157 and on Chrome 159 for Android (412 px touch, device pixel ratio 2.625).
- 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
<select>popup alignment when folded or torn, and TalkBack / VoiceOver focus order across the two halves.