A window that pours into the dock

Press the line in a window's title bar, or its button in the dock. The window bends into a funnel and pours into the button, and the button pours it back out. Both windows are <dialog> elements with real controls in them. Type in the notes, send the window away and bring it back, and what you typed is still there. The timer keeps counting while its window is in the dock.

After Genie Minimise by Raphael Salaja, which I found on Memorables. The effect is the one macOS uses for its Dock.

Notes
Timer
00:00.0

 

Show the code the markup, the funnel, the strips, the paint
  1. The markup. Two dialogs, each in a positioned wrapper, and a <nav> of buttons.
  2. The funnel. Where a row of the window goes at a given progress.
  3. The strips. One draw for each 2 px row, from a copy, by source rectangle or by clip.
  4. Open and close. The open attribute before the window pours out, dialog.close() after it has poured in.
  5. One picture. The window drawn once and copied into a plain canvas, for the copy route.
  6. The paint. A whole draw for a window at rest, strips for one that's moving, and the dock on top.
  7. Styles.
  8. The whole library file.

How it works

One canvas draws three elements: two wrappers that each hold a <dialog>, and the dock. A window at rest is one drawElementImage() call.

A window that's moving is drawn as rows 2 pixels tall, up to 92 of them for the notes. For each row the page works out where it is in the funnel: how far down, how wide and how far across. The sides bend in towards the dock button first, and the rows then slide down between them. Each row is one draw with nine arguments: a source rectangle inside the element and a destination rectangle on the canvas.

The second route draws the whole element once for each row, scaled and clipped to that row.

Both of those ask the browser to draw the window's picture about 90 times a frame, each time at a different scale. On my phone that was slow and uneven. So the page starts on a third route: it draws the window once, copies those pixels into a plain canvas with drawImage(), and then copies strips out of that canvas. The copy is taken when the movement starts, so the timer's digits don't change while its window is in flight.

The menu under the demo switches between the three, and the line under it reports the paints and the longest gap between two paints for the last movement. The same line is sent to this site's report log.

Open and closed are the dialog's own states. When a window has poured in, the page calls dialog.close(). A closed dialog has no box, so the canvas has nothing to draw and the keyboard can't reach its controls. To bring it back the page sets the open attribute, moves focus to the window's minimise button and draws strips from the first frame that has a picture. The dock button carries aria-expanded.

Input. The copy route never draws the window while it moves, so its hit box stays where the one whole draw put it. A draw with a source rectangle puts the element's hit box at the piece that was drawn, with the size of the piece. After 92 of them the box is one thin row near the dock. So on every route, while a window moves, the page shrinks its hit box to a point with updateElementGeometry(), and when the window is whole again one ordinary draw puts the box back.

Live checks

These run on their own dialogs in the corner of the window. None of them calls show(), because that moves focus. The dialogs have the open attribute in their markup.

Findings