From 0355c21254d6d452fd4afbec28db3e124bc1d61a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 14 Oct 2026 22:04:35 -0700 Subject: Media pager with a mouse: the wheel pages, ctrl+wheel zooms, arrows for the pointer. Adam reached for the scroll wheel in the pager on his laptop and nothing useful happened: a notch scrolled the snap container a hundred pixels and the glide's snap put it straight back (a headless probe of the live pager: scrollTop stays 0), so the arrow keys were the only desktop way through. Now a wheel notch is a step — down the next post, up the one before, a sideways notch (a trackpad's, or shift+wheel) along the post's pictures — with a 220 ms breath between steps so a spin of the wheel is a step or two, not five; a trackpad's run of small deltas is one step per run (its first 40 px, the rest until a pause is spent). Ctrl+wheel zooms the picture at the cursor, which is also what a trackpad's pinch arrives as in Chrome (attachZoom's new wheel: 'ctrl' mode, 0.004 per unit); while zoomed the plain wheel pans it, and at 1× it is the pager's again. And where there is a pointer to hover with (hover: hover and pointer: fine), arrows: up and down at the right edge, left and right when the post has a picture that way (has-left/has-right, set as the slide on screen changes), faint until the pointer is over the pager. The keys, the wheel and the arrows share one step (pagerStep). No mouse drag-flick: discrete steps suit a pager. tools/pager-wheel-test.js (CDP mouseWheel is always a 120-unit notch to Chrome, so a trackpad run is dispatched page-side; headless has no hovering pointer, so one is given with --blink-settings); feed-picture-pager and image-zoom tests pass. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01J1Kon8bxJoHRpJdSzshCkp --- src/app.js | 9 ++- src/features/messages.js | 90 +++++++++++++++++++----- src/i18n.js | 4 ++ src/style.css | 20 ++++++ tools/pager-wheel-test.js | 172 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 276 insertions(+), 19 deletions(-) create mode 100644 tools/pager-wheel-test.js diff --git a/src/app.js b/src/app.js index 3cdb59e..7f6baa3 100644 --- a/src/app.js +++ b/src/app.js @@ -695,9 +695,16 @@ function attachZoom(box, img, { wheel = true } = {}) { if (e.target.closest('.lightbox-x')) return; if (moved) { moved = false; e.stopImmediatePropagation(); e.preventDefault(); return; } }, true); + // The wheel. true: a turn zooms (the lightbox, a picture on its own). + // 'ctrl': ctrl+wheel zooms — a trackpad's pinch arrives in Chrome as + // exactly that — and a plain wheel pans the picture while it is zoomed; + // at 1× a plain wheel is left to whoever owns the box (the pager pages). if (wheel) box.addEventListener('wheel', (e) => { + const zoom = wheel !== 'ctrl' || e.ctrlKey || e.metaKey; + if (!zoom && s <= 1) return; e.preventDefault(); - zoomAt(s * Math.exp(-e.deltaY * 0.002), e.clientX, e.clientY); + if (zoom) zoomAt(s * Math.exp(-e.deltaY * (wheel === 'ctrl' ? 0.004 : 0.002)), e.clientX, e.clientY); + else { x -= e.deltaX; y -= e.deltaY; } clamp(); apply(false); }, { passive: false }); } diff --git a/src/features/messages.js b/src/features/messages.js index a8815b0..7760654 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -12177,7 +12177,7 @@ export function messagesFeature(ctx) { slide._ev = ev; slide._rowId = it.row ? it.row.id : ev.id; // the feed row to land on (a repost's wrapper, not its inner post) // pinch to zoom a picture (drag pans it zoomed; the wheel is the pager's) - if (!video && ctx.attachZoom) ctx.attachZoom(slide, media, { wheel: false }); + if (!video && ctx.attachZoom) ctx.attachZoom(slide, media, { wheel: 'ctrl' }); // ctrl+wheel (a pinch) zooms; the plain wheel is the pager's if (video) { guardPicture(media, url); media.muted = !pagerLoud; @@ -12470,6 +12470,33 @@ export function messagesFeature(ctx) { return y ? box.scrollTop + r.top - b.top : box.scrollLeft + r.left - b.left; }; const pagerHold = (box) => { if (box && box._glide) { cancelAnimationFrame(box._glide); box._glide = 0; } }; + // the slide on screen — named, not "a screen further", which from a + // scroll still settling landed short + const pagerHere = () => pager && (pagerSlides().find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.left) < r.width / 2 && Math.abs(r.top) < r.height / 2; }) || pager.cur); + // A step: v up or down the posts (-1/1), hz along the post's pictures. + // The keys, the wheel and the desktop arrows all come here. + function pagerStep(v, hz) { + if (!pager) return false; + const here = pagerHere(); + if (v) { + const from = pager.onTail || !here ? pager.tail : here.closest('.mp-group'); + const to = from && (v > 0 ? from.nextElementSibling : from.previousElementSibling); + if (to) pagerGlide(pager.scroller, 'y', pagerAt(pager.scroller, to, true)); + return !!to; + } + if (hz) { + const to = !pager.onTail && here && (hz > 0 ? here.nextElementSibling : here.previousElementSibling); + if (to) pagerGlide(here.parentElement, 'x', pagerAt(here.parentElement, to, false)); + return !!to; + } + return false; + } + // the sideways arrows show only where the post has a picture that way + function pagerArrows(slide) { + if (!pager || !slide) return; + pager.el.classList.toggle('has-left', !!slide.previousElementSibling); + pager.el.classList.toggle('has-right', !!slide.nextElementSibling); + } function buildPager(want) { const video = want.kind === 'videos'; @@ -12479,7 +12506,48 @@ export function messagesFeature(ctx) { h('div', { class: 'mp-top' }, h('button', { class: 'mp-x', type: 'button', 'aria-label': t('close'), onClick: (e) => { e.stopPropagation(); dismissPager(); } }, '×'), video ? h('button', { class: 'mp-sound', type: 'button', onClick: (e) => { e.stopPropagation(); pagerSound(!pagerLoud); } }, - h('span', { class: 'on' }, '\u{1F50A}'), h('span', { class: 'off' }, '\u{1F507} ' + t('videoUnmute'))) : null)); + h('span', { class: 'on' }, '\u{1F50A}'), h('span', { class: 'off' }, '\u{1F507} ' + t('videoUnmute'))) : null), + // a mouse's way through (shown where there is a pointer to hover with, + // style.css): up and down the posts at the right edge, left and right + // along a post's pictures when it has more than one (has-left/right) + h('div', { class: 'mp-arrows' }, ...[['mp-up', 'pagerPrevPost', 'M6 15l6-6 6 6', -1, 0], ['mp-down', 'pagerNextPost', 'M6 9l6 6 6-6', 1, 0], + ['mp-ar-left', 'pagerPrevPic', 'M15 6l-6 6 6 6', 0, -1], ['mp-ar-right', 'pagerNextPic', 'M9 6l6 6-6 6', 0, 1]].map(([cls, label, d, v, hz]) => + h('button', { class: 'mp-arrow ' + cls, type: 'button', 'aria-label': t(label), title: t(label), onClick: (e) => { e.stopPropagation(); pagerStep(v, hz); } }, + h('span', { style: 'display:flex', html: '' }))))); + // A mouse wheel pages: a notch down is the next post, a notch up the one + // before, a breath between steps so a spin of the wheel doesn't skip + // five. A trackpad's run of small deltas is one step per run (its first + // 40px; the rest of the run, until a pause, is spent), and a sideways + // run — or shift+wheel — walks along the post's pictures. Ctrl+wheel (a + // trackpad's pinch comes the same way) zooms the picture and the wheel + // pans it while zoomed: attachZoom takes those first (defaultPrevented). + // Left to the browser, a notch scrolled the snap container a hundred + // pixels and the glide's snap put it straight back: the wheel did nothing. + let wheelStepAt = 0, run = null; + el.addEventListener('wheel', (e) => { + if (!pager || e.defaultPrevented || e.ctrlKey || e.metaKey) return; + if (e.target.closest && e.target.closest('.mp-caption.open, .mp-seek')) return; + e.preventDefault(); + const k = e.deltaMode === 1 ? 40 : 1; + let dx = e.deltaX * k, dy = e.deltaY * k; + if (e.shiftKey && !dx) { dx = dy; dy = 0; } + const hz = Math.abs(dx) > Math.abs(dy), d = hz ? dx : dy; + if (!d) return; + const notch = e.deltaMode === 1 || (hz ? e.wheelDeltaX && e.wheelDeltaX % 120 === 0 : e.wheelDeltaY && e.wheelDeltaY % 120 === 0); + const now = e.timeStamp; + if (notch) { + if (now - wheelStepAt < 220) return; + } else { + if (!run || now - run.at > 150) run = { at: now, acc: 0, done: false }; + run.at = now; + if (run.done) return; + run.acc += d; + if (Math.abs(run.acc) < 40) return; + run.done = true; + } + wheelStepAt = now; + pagerStep(hz ? 0 : Math.sign(d), hz ? Math.sign(d) : 0); + }, { passive: false }); // A touch is the pager's to judge, not the browser's. Left to native // scrolling, a tap whose finger moved a few pixels was taken for a // scroll (no click: a tap meant to pause a clip did nothing), and a quick @@ -12635,6 +12703,7 @@ export function messagesFeature(ctx) { } pager.cur = e.target; pager.curAt = Date.now(); + pagerArrows(e.target); if (pager.fromFeed) { const row = feedNow().notes.find((x) => x.id === e.target._rowId); markSeen(row || e.target._ev); } playSlide(e.target); pagerCounts(e.target); @@ -12749,22 +12818,7 @@ export function messagesFeature(ctx) { // up and down: the next post, or the one before; left and right: along this post's row const v = ['ArrowDown', 'j', 'PageDown'].includes(e.key) ? 1 : ['ArrowUp', 'k', 'PageUp'].includes(e.key) ? -1 : 0; const hz = ['ArrowRight', 'l'].includes(e.key) ? 1 : ['ArrowLeft', 'h'].includes(e.key) ? -1 : 0; - // to the slide (or post) next to the one on screen — named, not "a - // screen further", which from a scroll still settling landed short - const here = pagerSlides().find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.left) < r.width / 2 && Math.abs(r.top) < r.height / 2; }) || pager.cur; - if (v) { - e.preventDefault(); - const from = pager.onTail || !here ? pager.tail : here.closest('.mp-group'); - const to = from && (v > 0 ? from.nextElementSibling : from.previousElementSibling); - if (to) pagerGlide(pager.scroller, 'y', pagerAt(pager.scroller, to, true)); - return; - } - if (hz) { - e.preventDefault(); - const to = !pager.onTail && here && (hz > 0 ? here.nextElementSibling : here.previousElementSibling); - if (to) pagerGlide(here.parentElement, 'x', pagerAt(here.parentElement, to, false)); - return; - } + if (v || hz) { e.preventDefault(); pagerStep(v, hz); return; } if (e.key === ' ' && pager.cur) { const v = pager.cur.querySelector('video.mp-media'); if (v) { e.preventDefault(); if (v.paused) v.play().catch(() => {}); else v.pause(); } diff --git a/src/i18n.js b/src/i18n.js index 82004a2..fd192a1 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -274,6 +274,10 @@ const STR = { pagerFetchingVideo: "Fetching the next video…", pagerFetchingPictures: "Fetching more pictures…", pagerCaughtUp: "That’s everything for now", + pagerPrevPost: 'Previous post', + pagerNextPost: 'Next post', + pagerPrevPic: 'Previous picture', + pagerNextPic: 'Next picture', videoNoPicture: "This browser can’t show this video’s picture", videoOpenFile: "Open the file", videoLargeTitle: "Videos", diff --git a/src/style.css b/src/style.css index f908a05..c581535 100644 --- a/src/style.css +++ b/src/style.css @@ -1546,6 +1546,26 @@ body::after { } .mp-sound { font-size: 15px; } .mp-sound .off { display: none; } +/* A mouse's way through the pager: arrows, where there is a pointer to + hover with (a phone swipes). Faint until the pointer is over the pager; + the sideways pair only when the post has a picture that way. */ +.mp-arrows { display: none; } +@media (hover: hover) and (pointer: fine) { + .mp-arrows { display: contents; } + .mp-arrow { + position: absolute; z-index: 3; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; + display: flex; align-items: center; justify-content: center; cursor: pointer; + color: #fff; background: rgba(255, 255, 255, .14); opacity: .4; transition: opacity .15s, background .15s; + } + .mp-arrow svg { width: 26px; height: 26px; } + .media-pager:hover .mp-arrow { opacity: .8; } + .mp-arrow:hover { opacity: 1; background: rgba(255, 255, 255, .28); } + .mp-up { right: 14px; top: calc(50% - 50px); } + .mp-down { right: 14px; top: calc(50% + 6px); } + .mp-ar-left { left: 14px; top: calc(50% - 22px); } + .mp-ar-right { right: 72px; top: calc(50% - 22px); } + .media-pager:not(.has-left) .mp-ar-left, .media-pager:not(.has-right) .mp-ar-right { display: none; } +} .media-pager.quiet .mp-sound .on { display: none; } .media-pager.quiet .mp-sound .off { display: inline; } /* muted against our will: the button stays up so the way to sound is plain */ diff --git a/tools/pager-wheel-test.js b/tools/pager-wheel-test.js new file mode 100644 index 0000000..b73171b --- /dev/null +++ b/tools/pager-wheel-test.js @@ -0,0 +1,172 @@ +// The media pager with a mouse (a laptop): a wheel notch is a step — down +// the next post, up the one before, sideways (or shift+wheel) along a post's +// pictures — a trackpad's run of small deltas one step per run, a spin of +// the wheel not five; ctrl+wheel (a trackpad's pinch) zooms the picture, +// the wheel pans it while zoomed and pages again at 1×; and arrows at the +// edges for the pointer, the sideways pair only where the post has more. +// Run: bun tools/pager-wheel-test.js +import puppeteer from './puppeteer.js'; +import { cacheKeyFor } from '../src/wallet.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { buildHtml } from '../build.js'; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; +const png = (size) => Bun.spawnSync(['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=' + size, '-frames:v', '1', '-f', 'image2', '-c:v', 'png', 'pipe:1']).stdout; +const PICS = { a1: png('400x300'), a2: png('300x400'), b: png('320x320'), d: png('360x240') }; + +const SK = generateSecretKey(), AUTHOR = getPublicKey(SK); +const now = Math.floor(Date.now() / 1000); +const post = (content, ago) => finalizeEvent({ kind: 1, created_at: now - ago, tags: [], content }, SK); +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 0, fetch: (req) => { + const path = new URL(req.url).pathname; + if (path.startsWith('/punks')) return new Response(Bun.file('dist' + path)); + const m = /^\/(a1|a2|b|d)\.png$/.exec(path); + if (m) return new Response(PICS[m[1]], { headers: { 'content-type': 'image/png' } }); + return new Response(html, { headers: { 'content-type': 'text/html' } }); +} }); +const U = (n) => server.url.origin + '/' + n + '.png'; +const seeded = [ + post('two pictures ' + U('a1') + ' ' + U('a2'), 100), + post('one picture ' + U('b'), 200), + post('only words here, nothing to look at', 300), + post('a last picture ' + U('d'), 400), + ...Array.from({ length: 12 }, (_, i) => post('filler ' + i + ' ' + 'lorem ipsum dolor sit amet. '.repeat(5), 500 + i * 60)), +]; + +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox', '--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4'] /* a pointer that hovers: headless has none */ }); +const page = await browser.newPage(); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t); +const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; }; +const waitFor = async (fn, arg, ms = 10000) => { for (let i = 0; i < ms / 100; i++) { if (await page.evaluate(fn, arg)) return true; await sleep(100); } return false; }; +// the slide the pager rests on, by its picture +const curPic = () => page.evaluate(() => { + const sc = document.querySelector('.mp-scroll'); if (!sc) return null; + const s = [...sc.querySelectorAll('.mp-slide')].find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.top) < 4 && Math.abs(r.left) < 4; }); + return s ? s.getAttribute('data-k').split('|')[1].split('/').pop() : 'between'; +}); +const resting = async (name) => rested(name).then(async (r) => { await sleep(260); return r; }); // a breath after: the wheel's gate between steps +const rested = async (name) => waitFor((n) => { const sc = document.querySelector('.mp-scroll'); if (!sc) return false; const s = [...sc.querySelectorAll('.mp-slide')].find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.top) < 4 && Math.abs(r.left) < 4; }); return !!s && s.getAttribute('data-k').endsWith('/' + n); }, name, 4000); +const openPic = async (word) => { + await page.evaluate((w) => { const r = [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.textContent.includes(w)); r.scrollIntoView({ block: 'center' }); }, word); + await sleep(400); + const at = await page.evaluate((w) => { const r = [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.textContent.includes(w)); const i = r.querySelector('img.note-img').getBoundingClientRect(); return { x: i.x + i.width / 2, y: i.y + i.height / 2, y0: window.scrollY }; }, word); + await page.mouse.click(at.x, at.y); + await waitFor(() => !!document.querySelector('.media-pager'), null, 4000); + return at.y0; +}; +const tapPager = async () => { const at = await page.evaluate(() => { const sc = document.querySelector('.mp-scroll'); const s = [...sc.querySelectorAll('.mp-slide')].find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.top) < 4 && Math.abs(r.left) < 4; }) || sc.firstChild; const r = s.querySelector('img.mp-media').getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; }); await page.mouse.click(at.x, at.y); }; +const rowTop = (word) => page.evaluate((w) => { const r = [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.textContent.includes(w)); return r ? Math.round(r.getBoundingClientRect().top) : null; }, word); + +try { + await page.setViewport({ width: 1280, height: 900 }); + await page.goto(server.url.href, { waitUntil: 'domcontentloaded' }); + await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); + await page.reload({ waitUntil: 'domcontentloaded' }); + await sleep(400); + await click('create a new wallet'); await sleep(600); + await page.waitForSelector('.words .w .t'); + const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' '); + await click('skip verification'); + await waitText('receive', 20000); + const base = cacheKeyFor(mn + '\n'); + await page.evaluate(([k, pk, ns]) => { + localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', pk]], c: '', at: Math.floor(Date.now() / 1000) })); + localStorage.setItem(k + ':feedNotes', JSON.stringify(ns)); + localStorage.setItem(k + ':profiles', JSON.stringify({ [pk]: { name: 'Picture Poster', t: Date.now() } })); + localStorage.setItem('btc-wallet-feed:' + k, 'following'); + }, [base, AUTHOR, seeded]); + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]').click()); + check('the pictures are in the feed', await waitFor(() => document.querySelectorAll('.notes-feed img.note-img').length >= 4, null, 20000)); + const cdp = await page.target().createCDPSession(); + // a trackpad's run: small deltas, page-side — a CDP mouseWheel is always a 120-unit notch to Chrome + const pad = (dy, n) => page.evaluate(async ([dy, n]) => { const sc = document.querySelector('.mp-scroll'); for (let i = 0; i < n; i++) { const s = [...sc.querySelectorAll('.mp-slide')].find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.top) < 4 && Math.abs(r.left) < 4; }) || sc.firstChild; const ev = new WheelEvent('wheel', { deltaY: dy, deltaX: 0, deltaMode: 0, bubbles: true, cancelable: true, clientX: 640, clientY: 450 }); Object.defineProperty(ev, 'wheelDeltaY', { value: -Math.round(dy * 1.2) }); s.querySelector('img.mp-media').dispatchEvent(ev); await new Promise((r) => setTimeout(r, 16)); } }, [dy, n]); + const pos = () => page.evaluate(() => { const sc = document.querySelector('.mp-scroll'); return sc ? Math.round(sc.scrollTop) + '/' + sc.clientHeight + ' glide:' + !!sc._glide + ' snap:' + sc.style.scrollSnapType : 'none'; }); + const wheel = (dy, { dx = 0, mods = 0 } = {}) => cdp.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: 640, y: 450, deltaX: dx, deltaY: dy, modifiers: mods }); + const zoomOf = () => page.evaluate(() => { const sc = document.querySelector('.mp-scroll'); const s = [...sc.querySelectorAll('.mp-slide')].find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.top) < 4 && Math.abs(r.left) < 4; }); const m = /scale\(([\d.]+)\)/.exec(s.querySelector('img.mp-media').style.transform || ''); return m ? Number(m[1]) : 1; }); + const shiftOf = () => page.evaluate(() => { const sc = document.querySelector('.mp-scroll'); const s = [...sc.querySelectorAll('.mp-slide')].find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.top) < 4 && Math.abs(r.left) < 4; }); const m = /translate\(([-\d.]+)px, ([-\d.]+)px\)/.exec(s.querySelector('img.mp-media').style.transform || ''); return m ? [Number(m[1]), Number(m[2])] : [0, 0]; }); + + console.log('\n[a wheel notch is a step]'); + await openPic('two pictures'); + check('the picture opens in the pager', await resting('a1.png'), await curPic()); + await page.mouse.move(640, 450); + await wheel(100); + check('a notch down: the next post\'s picture', await resting('b.png'), await curPic()); + await wheel(100); + check('another: the next, past a post with none', await resting('d.png'), await curPic()); + await wheel(-100); + check('a notch up: back one post', await resting('b.png'), await curPic()); + await wheel(-100); + check('up again: the first post', await resting('a1.png'), await curPic()); + await wheel(0, { dx: 100 }); + check('sideways: the post\'s second picture', await resting('a2.png'), await curPic()); + await wheel(0, { dx: 100 }); await sleep(300); + check('sideways at the post\'s last: stays', (await curPic()) === 'a2.png', await curPic()); + await wheel(-100, { mods: 8 }); + check('shift+wheel up: back to its first picture', await resting('a1.png'), await curPic()); + await wheel(-100, { mods: 8 }); await sleep(300); + check('shift+wheel at the first: stays', (await curPic()) === 'a1.png', await curPic()); + await wheel(100, { mods: 8 }); await resting('a2.png'); + await sleep(300); + for (let i = 0; i < 5; i++) { await wheel(100); await sleep(10); } + await sleep(700); + check('a spin of five notches in a blink is a step or two, not five', ['b.png', 'd.png'].includes(await curPic()), await curPic()); + await wheel(-100); await resting('b.png'); await wheel(-100); await resting('a2.png'); await wheel(100); await resting('b.png'); + + console.log('\n[a trackpad\'s run is one step]'); + await sleep(300); + await pad(9, 14); + check('a run of small deltas steps once', await resting('d.png'), await curPic() + ' ' + await pos()); + await sleep(400); + check('…and only once', (await curPic()) === 'd.png', await curPic()); + await sleep(300); + await pad(-9, 14); + check('a run back steps back', await resting('b.png'), await curPic()); + + console.log('\n[ctrl+wheel zooms, the wheel pans, 1× pages]'); + await sleep(400); + await wheel(-100, { mods: 2 }); await sleep(100); + const z1 = await zoomOf(); + check('ctrl + a notch up zooms the picture in', z1 > 1.2, 'scale ' + z1); + await wheel(-100, { mods: 2 }); await sleep(100); + check('…and more', (await zoomOf()) > z1, 'scale ' + await zoomOf()); + const before = await shiftOf(); + await wheel(100); await sleep(300); + check('a plain notch while zoomed pans, it does not page', (await curPic()) === 'b.png' && JSON.stringify(await shiftOf()) !== JSON.stringify(before), await curPic() + ' ' + JSON.stringify(before) + ' → ' + JSON.stringify(await shiftOf())); + for (let i = 0; i < 6; i++) { await wheel(100, { mods: 2 }); await sleep(30); } + await sleep(100); + check('ctrl + notches down zoom back out to 1×', (await zoomOf()) === 1, 'scale ' + await zoomOf()); + await sleep(300); + await wheel(100); + check('at 1× the wheel pages again', await resting('d.png'), await curPic()); + + console.log('\n[arrows for the pointer]'); + const shown = (sel) => page.evaluate((s) => { const b = document.querySelector(s); return !!b && getComputedStyle(b).display !== 'none' && b.getBoundingClientRect().width > 0; }, sel); + check('up and down arrows are on the pager', await shown('.mp-arrow.mp-up') && await shown('.mp-arrow.mp-down')); + check('a post with one picture shows no sideways arrows', !(await shown('.mp-arrow.mp-ar-left')) && !(await shown('.mp-arrow.mp-ar-right'))); + await page.click('.mp-arrow.mp-up'); + check('the up arrow: back one post', await resting('b.png'), await curPic()); + await page.click('.mp-arrow.mp-up'); + check('up again: the first post, on the picture it was left at', await resting('a2.png'), await curPic()); + await sleep(200); + check('on its last picture: a left arrow, no right', await shown('.mp-arrow.mp-ar-left') && !(await shown('.mp-arrow.mp-ar-right'))); + await page.click('.mp-arrow.mp-ar-left'); + check('the left arrow: its first picture', await resting('a1.png'), await curPic()); + await sleep(200); + check('on its first: a right arrow, no left', await shown('.mp-arrow.mp-ar-right') && !(await shown('.mp-arrow.mp-ar-left'))); + await page.click('.mp-arrow.mp-ar-right'); + check('the right arrow: its second picture', await resting('a2.png'), await curPic()); + check('an arrow\'s click is not a tap on the picture (no details, still open)', await page.evaluate(() => { const p = document.querySelector('.media-pager'); return !!p && !p.classList.contains('show'); })); + await page.click('.mp-arrow.mp-down'); + check('the down arrow: the next post', await resting('b.png'), await curPic()); + await page.keyboard.press('Escape'); + check('Escape still closes it', await waitFor(() => !document.querySelector('.media-pager') && !!document.querySelector('.notes-feed'), null, 3000)); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} catch (e) { console.error(e); ok = false; } finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ pager: wheel steps, ctrl+wheel zooms, arrows for the pointer' : '\n❌ failed'); +process.exit(ok ? 0 : 1); -- cgit v1.2.3