| 36 | }; |
| 37 | |
| 38 | const onScroll = () => { |
| 39 | // A sheet pins the body while it is open, which reads as a jump to the |
| 40 | // top; the bars keep the state they had. |
| 41 | if (document.body.style.position === 'fixed') { |
| 42 | return; |
| 43 | } |
| 44 | const y = window.scrollY; |
| 45 | const delta = y - lastY; |
| 46 | lastY = y; |
| 47 | |
| 48 | // While the drawer is up to its full page the block stays in place over |
| 49 | // it; reading on down the post it hides and returns as on any page, as |
| 50 | // X's bar does. |
| 51 | const { classList } = document.documentElement; |
| 52 | if ( |
| 53 | (classList.contains('reading') && !classList.contains('reading-past')) || |
| 54 | performance.now() < expectedUntil |
| 55 | ) { |
| 56 | armed = 0; |
| 57 | emit(rest); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | if (y <= deadZone) { |
| 62 | armed = 0; |
| 63 | emit(rest); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | armed = Math.sign(armed) === Math.sign(delta) ? armed + delta : delta; |
| 68 | if (armed > scroll.hideTolerance) { |
| 69 | emit(away); |
| 70 | } else if (armed < -scroll.revealTolerance) { |
| 71 | emit(rest); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | const subscribe = (listener: () => void) => { |
| 76 | if (listeners.size === 0) { |